1675 posts Envato Elite Author
  • Elite Author
  • Sold between 100 000 and 250 000 dollars
  • Author had a Free File of the Month
  • Exclusive Author
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
  • Europe
  • Has been a member for 4-5 years
  • Referred between 10 and 49 users
+1 more
Tean says

This is my code:


<div id="circle">
   <div id="inner"></div>
</div>

#circle{
position:relative;
display:block;
width:100px;
height:100px;
background:black;

border-radius:50px;
-moz-border-radius:50px;
-webkit-border-radius:50px;

overflow:hidden;

}

#inner {
position:absolute;
width:100px;
height:30px;

background:yellow;
top:0px;
left:0px;

}

I am trying to achive the first picture, and it works in FF and IE9 , but fails in Safari, Chrome and Opera where I get second picture.

Is there a way to make this cross browser?

Thank you

42 posts
  • Elite Author
  • Exclusive Author
  • Has been a member for 4-5 years
  • India
  • Referred between 50 and 99 users
  • Sold between 50 000 and 100 000 dollars
cosmocoder says

This is a known bug in Webkit, and also seems Opera is affected by it. I found this thread in Stackoverflow where it was discussed: http://stackoverflow.com/questions/6144398/rounded-corners-fail-to-cut-off-content-in-webkit-browsers-if-positionrelative

The solution is to remove the position relative declaration form the outer container. You have to position the inner element using margins then. This then works as intended in Webkit, but sadly not in Opera. Hopefully all browsers will fix this bug soon.

1675 posts Envato Elite Author
  • Elite Author
  • Sold between 100 000 and 250 000 dollars
  • Author had a Free File of the Month
  • Exclusive Author
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
  • Europe
  • Has been a member for 4-5 years
  • Referred between 10 and 49 users
+1 more
Tean says

Thanks for the reply!

So in other words this cant be done?

I dont even want to ask about IE7 and 8 :D

42 posts
  • Elite Author
  • Exclusive Author
  • Has been a member for 4-5 years
  • India
  • Referred between 50 and 99 users
  • Sold between 50 000 and 100 000 dollars
cosmocoder says

It seems that there is no fix for it, at least not for Opera. It will work in Firefox, IE9 and also in Webkit if you remove the position relative declaration.

IE7 and 8 does not support border radius, so no need to worry there :)

by
by
by
by
by
by