This website may use cookies. More info. That's Fine x
Welcome Login

Css rounded corners


CSS3 border-radius property allows web developers to easily round corners in their design, without the need for corner images or the use of multiple div tags.

Until CSS3 becomes more commonly supported, you can also use the -moz- prefix for Firefox support, and -webkit- for Safari/Chrome support.

 

 

border-radius property:

border-radius shorthand property can be used to define all four corners simultaneously.

The property accepts either one or two sets of values, each consisting of one to four lengths or percentages.

Syntax:

border-radius: [ <length> | <percentage> ]{1,4} [ / [ <length> | <percentage> ]{1,4} ]?

 

Eg:

border-radius: 5px 10px 5px 10px / 10px 5px 10px 5px;
border-radius: 5px;
border-radius: 5px 10px / 10px;

 

The first set of (1-4) values define the horizontal radii for all four corners.

An optional second set of values, preceded by a '/', define the vertical radii for all four corners.

If only one set of values are supplied, these are used to determine both the vertical and horizontal equally.

For each set of values the following applies:

If all four values are supplied, these represent the top-left, top-right, bottom-right and bottom-left radii respectively.

If bottom-left is omitted it is the same as top-right, if bottom-right is omitted it is the same as top-left, and if only one value is supplied it is used to set all four radii equally.

 

 

Individual rounded corners:

Rounder corners can be created independently using border-*-radius properties:

border-top-left-radius 
border-top-right-radius
border-bottom-left-radius 
border-bottom-right-radius

 

The border-*-radius properties can each accept either one or two values, expressed as a length or a percentage (percentages refer to the corresponding dimensions of the border box).

Eg:

border-top-left-radius: 10px 5px;
border-bottom-right-radius: 10% 5%;
border-top-right-radius: 10px; 

 

 

 

Examples:

Eg:

<html>

<head>

<style type="text/css">
.exampleborderradius {
  width:350px;
  height:100px;
  border:1px solid black;

  border-radius: 6px;
  -webkit-border-radius: 6px;
  -moz-border-radius: 6px;
}
</style>


</head>

<body>

<div class="exampleborderradius">This box should have a rounded corners for Firefox, Safari/Chrome, Opera and IE9.</div>

</body>

</html>

 

Outputs:

css-roundedcorners2

 

Eg2:

<html>

<head>

<style type="text/css">
.exampleborderradius {
  background-color: grey;
  width: 200px;
  height: 200px;
  padding: 30px;

  border-radius: 6px;
  -webkit-border-radius: 6px;
  -moz-border-radius: 6px;
}
</style>

</head>

<body>

<div class="exampleborderradius">This box should have a rounded corners for Firefox, Safari/Chrome, Opera and IE9.</div>

</body>

</html>

 

Outputs:

css-roundedcorners1

 

 

For auto-generating css code for css rounded corners, sse here.


Created on: Thursday, October 25, 2012 by Andrew Sin