Round corners have always helped to improve the look of a website. A website with round corners is considered more attractive than the one without any round corners. There are multiple ways of creating round corners and the most common approach is by using rounded images. In this article we will look at an alternative way of creating Round Corners using only CSS.

Introduction:

Round corners have always helped to improve the look of a website. A website with round corners is considered more attractive than the one without any round corners. There are multiple ways of creating round corners and the most common approach is by using rounded images. In this article we will look at an alternative way of creating Round Corners using only CSS.

What’s wrong with Using Images?

There is nothing wrong with using images to create round corners. The only problem is coming up with images. Developers are not usually trained to create small rounded images or even to change the background color of existing round corner images. For such scenarios a CSS approach is much suitable.

How we are going to do it?

This is a good question. We are going to use two rectangles and combine them in such a way that it will create round corner effects. It is hard to explain using words so take a look at the animation shown below:

 


Show me the CSS:

Well, it is about time. Take a look at the CSS shown below:

.span1
{

display:block;
position:relative;
margin:4px 1px;
border-width:1px 0;
border-style:solid;
text-decoration:none;
background-color:black;
}

.div1
{

display:block;
background-color:black;
margin:0 -1px;
padding:2px 16px;
color:white;

}

This CSS will help us to obtain the behavior we just saw in the animation above.

Making Round Corners:

The final step is to decorate your elements with the above CSS classes to create the round corner effect.

<span class="span1">
    
     <div class="div1">
    
     Round Corner Using Only CSS!
     </div>
    
     </span>

The SPAN tag is the outer container which is made rounded by the inner container using pixel indentation. Take a look at the final output below:

   

Conclusion:

In this article we learned how to create rounded corners by only using the power of the CSS. This technique will save the developers from creating four different rounded images and banging there head on the wall when the client demands a different background color.

I hope you enjoyed the article, happy programming!

References:

Nifty Rounded Edges Using CSS Only