orboro.net

Rounded corners with CSS, no images needed

by JD on Nov.19, 2008, under Development, Technology

Rounded corners are the craze with this Web2.0 stuff and I had to find a solution to create them with no images and no JavaScript.  Here’s how I did it.

The basic idea was to make colored lines to create the corners.

Here’s the HTML to get the corners:

  1. <div id="container">
  2. <b class="rtop">
  3.   <b class="r1"></b> <b class="r2"></b> <b class="r3"></b> <b class="r4"></b>
  4. </b>
  5. <!–content goes here –>
  6. <b class="rbottom">
  7.   <b class="r4"></b> <b class="r3"></b> <b class="r2"></b> <b class="r1"></b>
  8. </b>
  9. </div>

Here’s the CSS you’ll need:

  1. div#container {
  2.         width: 600px;
  3.         margin: 0 10%;
  4.         background: #FFF
  5. }
  6.  
  7. b.rtop, b.rbottom {
  8.         display: block;
  9.         background: #004da0;
  10. }
  11.  
  12. b.rtop b, b.rbottom b {
  13.         display: block;
  14.         height: 1px;
  15.     overflow: hidden;
  16.         background: #FFF;
  17. }
  18.  
  19. b.r1 {
  20.         margin: 0 5px;
  21. }
  22.  
  23. b.r2 {
  24.         margin: 0 3px;
  25. }
  26.  
  27. b.r3 {
  28.         margin: 0 2px;
  29. }
  30.  
  31. b.rtop b.r4, b.rbottom b.r4 {
  32.         margin: 0 1px;
  33.         height: 2px;
  34. }

I used the b element because it can be nested in almost every kind of tag and doesn’t have a semantic meaning.

  • Share/Bookmark
:, , , , ,

1 Comment for this entry

Leave a Reply

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!