HTML Remix - Dont copy code, remix it!

September 24, 2008

Curved corner (border-radius) cross browser

Posted by : Remiz
Filed under : CSS

Update 18 November , 2009: The htc file is updated by Nick F. Thanks man, you got time to check it out. Now supports FF, Chrome, Safari, IE6, IE7, IE8 (Os doesn’t matter).
This version of htc files can be found here and demo here


Update 17 August, 2009: This project is moved to Google Code. Please find the htc files on http://code.google.com/p/curved-corner. Links to htc file below will not work.


Update 16 July, 2009: htc file updated with support for IE8. Thanks to Kevin for coming up with a work-around. New htc file can be downloaded on border radius ie8.


Update 10 June, 2009: Some servers need to set MIME type for HTC to work this in IE6.
To do this, follow the steps.

1. Go to your cpanel and click the MIME Types link
2. Under MIME Type, add text/x-component
3. Under Extensions, add htc
4. Restart Apache Web server


As I’ve pledged, today I’m posting the Curved corner without any js stuff.

For firefox, you can set border-radius by prefixing “-moz” to the css property. And ofcource for webkit use “-webkit” . Now IE ?? .. As IE is not a good browser to work with css, we need to make it so. Here, you need to use a nice css hack. Some how I managed to have an htc file to make border-radius work in IE  :) . You can download it here. border-radius.htc .

The Demo

1 . I’ve just made: http://www.htmlremix.com/files/20080924-border-radius.zip

The CSS:

  1. .curved {
  2. -moz-border-radius:10px;
  3. -webkit-border-radius:10px;
  4. behavior:url(border-radius.htc);
  5. }

The HTML:

<div class="curved">Curvd div</div>

The explanation :

Do you really want an explanation for this simple 3 line css ?. I don’t think so. Ofcourse if you need, I can.

Browsers :

All browsers :)

  • Delicious 0
  • Comments (440)

440 Responses to “Curved corner (border-radius) cross browser”

  1. SeDo says:

    Thx, For IE fix

  2. richT says:

    thanks for the great script.
    I wanted curved corners *and* a box-shadow for IE.

    box-shadow for IE can usually be achieved using something like
    filter: progid:DXImageTransform.Microsoft.Shadow(color=#000000,direction=125,strength=2);

    see http://ole-laursen.blogspot.com/2009/08/using-css3-box-shadow-with-ie.html

    Combining the two didn’t work as IE applied the shadow to the text not the container.

    With an small addition to your script on line after line 92 the problem was solved.

    rect.style.filter = ‘progid:DXImageTransform.Microsoft.Shadow(color=#000000,direction=125,strength=2)’;

    hope that might be useful to someone else!

  3. Very good css technique

  4. Sampo says:

    The htc file seems to move the element to the background. I have a page where a menu with rounded corners floats partly on top of the white page content element. When I load it into IE7 the menu displays on top of the content with square edges and a fraction of a second later (after loading the htc I assume) it gets round corners but is positioned *behind* the content element. Adding a z-index to the menu didn’t help, nor did moving the menu HTML code to be after the page content.

  5. joe says:

    Hmm… .htc file doesn’t exist any longer!?
    (same with the .zip)

  6. Redwan says:

    This code only works in IE8, Mozilla, Safari

  7. Redwan says:

    I findout one nice solution from the site

    http://www.html.it/articoli/nifty/index.html

    Please do it is better than images setup.

  8. Redwan says:

    But it is not work in Google Chrome too..

  9. Partho says:

    Hey Guys,

    You guys are doing very good job :) keep it up…

    my best wishes with you.

    thnx

  10. Gixx says:

    Any chance to support background-image property along with the border-radius?

  11. AmilaDG says:

    It may be nice tutorial if working download link of http://www.htmlremix.com/files/20080924-border-radius.zip and border-radius.htc

  12. uh... says:

    This might work well for a person just wanting to surf around on the internet and see some neat curved cornered css items.

    The only problem is from the view of someone producing sites using this, what are we supposed to do ask every person browsing your site to start jacking around mime types… That becomes a bit of a problem with 80% of people. Its a lil complicated of a task to ask Joe Shmoe.

    How about Microsoft get its ass in gear and join in with the rest of the club.

  13. amac44 says:

    I got a black background over the text in my div , any ideas?

  14. amac44 says:

    spiffy corners is the best I’ve seen, no images, no JS, http://www.spiffycorners.com. But it’s a rounded box set into a rectangle, and you can’t control the radius (only the 5px button works). The idea could be extended I’m sure.

  15. mxworkz says:

    Unfortunately the problem with Opera still exists :-( In order to make it really cross-browser, we need to use SVG for defining the rounded areas about Opera. With this addition, it will be already a cross-browser solution.

  16. xyz says:

    In my site on header code this is work fine..but in my inner code this not work

  17. Elguapaul says:

    Excellent !! Thanks so much.

  18. yo says:

    Otherwise, to have corners rounded independently, you can use http://www.dillerdesign.com/experiment/DD_roundies/ but this is implemented using Javascript, not VML.

  19. Hippy says:

    This does not seem to work for me… what could I be doing wrong?
    I have IE 8 and my code for all the other browsers is working, but not IE.

    Thanks

  20. Lidocain says:

    @ iMezied :

    You can’t specify which corner to curve. This HTC for border-radius can only round the 4 corners at once with the same radius.
    It’s a limitation of Microsoft’s VML (used to make these rounded corners in IE 5-8). It’s “all rounded the same” or “none rounded” ;)

Leave a Reply