Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS Border radius not trimming image on Webkit

I'm having trouble figuring out why border-radius is gone from my #screen element when using chrome but not firefox or ie9?

I have all the different prefixes for each browser plus the standard border-radius:

www.cenquizqui.com

The upper content box that holds the pictures, called #screen

a copy paste of screen's css:

#screen {background: none repeat scroll 0 0 #EEEEEE;
    display: block;
    height: 300px;
    position: relative;
    width: 960px;
    overflow:hidden;
    -moz-border-radius:10px;
    -webkit-border-radius:10px;
    -o-border-radius:10px;
    border-radius:10px;}

Is it because chrome does not handle the 'trimming' of the images properly? I thought it was only a problem when you had the actual tags inside the rounded corner container, not when the img is called as background-image through css.

Regards G.Campos

like image 482
Capagris Avatar asked Jan 02 '12 20:01

Capagris


People also ask

How do I trim an image border in CSS?

CSS Syntax border-image-slice: number|%|fill|initial|inherit; Note: The border-image-slice property can take from one to four values. If the fourth value is omitted, it is the same as the second. If the third one is also omitted, it is the same as the first.

Should I use border-radius REM?

There is no technical reason not to use the rem unit for border-radius . Neither is never any compelling reason to use the rem unit, for it or otherwise.

How do you reset border-radius in CSS?

-webkit-border-radius: 0; -moz-border-radius: 0; -o-border-radius: 0; border-radius: 0; border: 0; That should reset the borders.


4 Answers

There is a much simpler solution.

Just add overflow:hidden to the container that has the border-radius and holds the child elements. This prevents the children 'flowing' over the container.. Thus fixing the problem and showing the border-radius

like image 195
DutchKevv Avatar answered Oct 24 '22 09:10

DutchKevv


Here's a workaround that will fix the current chrome bug:

.element-that-holds-pictures {
   perspective: 1px; /* any non-zero value will work */
}

This won't affect the display at all (unlike the opacity:0.99 workaround - which is great workaround, too, by the way).

like image 22
Adam Avatar answered Oct 24 '22 09:10

Adam


Webkit cannot handle border-radius cropping for children and grand-children+. It's just that bad. If you want border cropping, it has to be directly on the div the image is placed on without going any deeper down the hierarchy.

like image 9
Capagris Avatar answered Oct 24 '22 10:10

Capagris


Try the following css to the child elements of the element with border-radius set: opacity:0.99; It solves the problem and doesn't change the opacity much. This worked perfectly for me.

like image 1
kirtan-shah Avatar answered Oct 24 '22 08:10

kirtan-shah