Saturday, February 24, 2007

How to create rounded corner box using CSS

For a long time web designers were using table tags to create rounded corner tables or boxes. They all used the same method, three rows by three columns to be able to create flexible tables with rounded corner. This way is absolutely gone and we are no longer using it now, we are using the CSS method, which is easier and faster.


ONE

First thing is to prepare all your rounded corner images


Then create a normal <div> box
HTML:
<div class="box"></div>

CSS:
.box {width:200px; height:200px; background-color:#FFFFFF;}



TWO

After that we add the top left background to it, or whatever corner you would like to add. The CSS will be:
.box {
width:200px;
height:200px;
background-color:#FFFFFF;
background-image:url(images/tLeft.gif);
background-position:top left;
margin:0px; padding:0px;
background-repeat:no-repeat;
}

This is your progress till now:




THREE

Create another <div> tag inside the first one and add the top right background to it.
HTML:
<div class="box"><div class="tRight">
</div></div>

CSS:
.box {
width:200px;
height:200px;
background-color:#FFFFFF;
background-image:url(images/tLeft.gif);
background-position:top left;
margin:0px; padding:0px;
background-repeat:no-repeat;
}

.tRight
{
width:200px;
height:200px;
background-image:url(images/tRight.gif);
background-position:top right;
margin:0px; padding:0px;
background-repeat:no-repeat;
}

This is your progress till now:




FOUR

Create another <div> tag inside and add the bottom Right background to it.
HTML:
<div class="box"><div class="tRight"><div class="bRight">
</div></div></div>

CSS:
.box {
width:200px;
height:200px;
background-color:#FFFFFF;
background-image:url(images/tLeft.gif);
background-position:top left;
margin:0px; padding:0px;
background-repeat:no-repeat;
}

.tRight
{
width:200px;
height:200px;
background-image:url(images/tRight.gif);
background-position:top right;
margin:0px; padding:0px;
background-repeat:no-repeat;
}

.bRight
{
width:200px;
height:200px;
background-image:url(images/bRight.gif);
background-position:bottom right;
margin:0px; padding:0px;
background-repeat:no-repeat;
}

This is your progress till now:



FIVE and the LAST STEP

The last corner to add, do the same and add the forth <div> tag inside with the bottom left corner in the backround of it.

HTML:
<div class="box"><div class="tRight"><div class="bRight"><div class="bLeft">
</div></div></div></div>

CSS:
.box {
width:200px;
height:200px;
background-color:#FFFFFF;
background-image:url(images/tLeft.gif);
background-position:top left;
margin:0px; padding:0px;
background-repeat:no-repeat;
}

.tRight
{
width:200px;
height:200px;
background-image:url(images/tRight.gif);
background-position:top right;
margin:0px; padding:0px;
background-repeat:no-repeat;
}

.bRight
{
width:200px;
height:200px;
background-image:url(images/bRight.gif);
background-position:bottom right;
margin:0px; padding:0px;
background-repeat:no-repeat;
}

.bLeft
{
width:200px;
height:200px;
background-image:url(images/bLeft.gif);
background-position:bottom left;
margin:0px; padding:0px;
background-repeat:no-repeat;
}

This is your final output:



EXAMPLE

The online HTML example here

6 Comments:

Blogger Unknown said...

Thank you Mostafa for your great contributions. I wish you all the best in life and after inshallah

February 26, 2007 at 1:50 PM  
Blogger suresh said...

thank u very much mr. mostafa. Really its very easy to understand and to follow the steps.

All best...

January 18, 2008 at 8:44 AM  
Anonymous Anonymous said...

Your site helped me understand the basic elements of how to design 'table-less' corners using CSS. Thank you!

March 8, 2008 at 12:26 AM  
Blogger Unknown said...

How i create a css round box using 8 images.(top left,top right,top middle,left,right,bottom left,bottom middle,bottom right).

May 30, 2008 at 11:34 AM  
Anonymous Anonymous said...

thanx 4 sharing a very useful tip keep doing a great works.

November 7, 2008 at 1:31 PM  
Anonymous iPhone Deals said...

Thanks for giving the good and helpful information on how to create the round corner boxes.

December 1, 2009 at 10:31 AM  

Post a Comment

Subscribe to Post Comments [Atom]

<< Home