Library tutorials & articles

CSS and round corners: Boxes with curves

Bottom & Top Curves

Bottom right curve

Next, we'll stick in that bottom-right curve. As previously mentioned, we can only assign one background image to each <div> in the CSS so we'll need to insert a new <div>:

<div class="bl"><div class="br">
Lorem ipsum dolor sit amet consectetur adipisicing elit
</div></div>

Naming our bottom-right image (Bottom-right curve), br.gif, we'll insert a new CSS rule:

.br {background: url(br.gif) 100% 100% no-repeat}

This CSS rule is essentially the same as our last one, but now we've changed the position from the left to 100%, where previously it was 0%. Our box now looks like:

Lorem ipsum dolor sit amet consectetur adipisicing elit

Top curves

To make our top curves we'll need two new images, Top-left curve and Top-right curve, which we'll call tl.gif and tr.gif. We'll then need to create two new <div>s for them:

<div class="bl"><div class="br"><div class="tl"><div class="tr">
Lorem ipsum dolor sit amet consectetur adipisicing elit
</div></div></div></div>

And our new CSS rules:

.tl {background: url(tl.gif) 0 0 no-repeat}
.tr {background: url(tr.gif) 100% 0 no-repeat}

Giving us:

Lorem ipsum dolor sit amet consectetur adipisicing elit

Background colour

We'll now insert our orange background colour into the box, so as to achieve the whole round corners effects. The background colour must always be assigned to the very first CSS rule. This is because each CSS background rule is essentially a layer on top of the previous one. So, in this example we have a layering order of br.gif, bl.gif, tl.gif and then tr.gif. In this example the images don't overlap so we don't really notice this layering effect.

A background colour by default covers the entire <div> and will layer on top of any other previously assigned background images and/or colours. Therefore, if we place the orange colour in any <div> other than the first it will be placed on top of the preceding images and will essentially cause them to disappear. Therefore, we must place our orange background colour (#e68200) in the very first CSS rule:

.bl {background: url(bl.gif) 0 100% no-repeat #e68200; width: 20em}

As before, it doesn't matter where we place this colour command within the CSS background rule. Our box now looks like:

Lorem ipsum dolor sit amet consectetur adipisicing elit

Comments

  1. 08 Oct 2008 at 20:27
    Thanks, great tut. user might like to create rounded corners without images. just pure css. http://www.cssroundedcorners.co.uk
  2. 17 Sep 2008 at 09:26

    Thank you. I like it and use it in my project. very simple but useful. Smiley Face

  3. 01 Jan 1999 at 00:00

    This thread is for discussions of CSS and round corners: Boxes with curves.

Leave a comment

Sign in or Join us (it's free).

Trenton Moss This article was written by Trenton Moss. Trenton's crazy about web accessibility and usability - so crazy that he went and started his own web accessibility and usability consultancy to help make ...
AddThis

Related podcasts

  • Despise the listener

    We have a great lineup this week: Paul talks about getting things done in web design and an alternative approach to your reading list. Marcus explains the exciting area of insurance for web designers and we have Andy Clarke on the show to give us an update on CSS 3.

Events coming up

  • Nov 23

    Dan Cederholm Workshop

    London, United Kingdom

    Handcrafted Bulletproof CSSwith Dan Cederholm of "Simplebits"Learn how craftsmanship can apply to the intangibility of web design. Dan Cederholm will guide you though a case study, pointing out the details that matter most when designing fle...

We'd love to hear what you think! Submit ideas or give us feedback