Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

overflow:hidden ignored with border-radius and CSS transforms (webkit only)

Tags:

I want to have a square image inside a circle.

When the user hovers over the image, the image should scale (zoom in).

The circle should remain the same size.

Only during the CSS transition, the square image overlaps the circle (as if overflow:hidden weren't there at all).

Here's a demo with the weird behavior in Chrome and Safari: http://codepen.io/jshawl/full/flbau

Working ok in firefox.

like image 776
jshawl Avatar asked Jun 01 '13 23:06

jshawl


2 Answers

You need to add this code to the parent of your img :

position:relative;
z-index:1;

Example here : http://codepen.io/DavidN/pen/dIzJK

like image 147
David Nazar Avatar answered Jan 18 '23 23:01

David Nazar


I removed some superfluous markup (the circle and square containers... only needs one) and styled the img itself:

#wrapper {
  width: 500px;
  height: 500px;
  border-radius: 50%;
  overflow: hidden;
  -webkit-mask-image: -webkit-radial-gradient(circle, white, black);
}

#test {
  width: 100%;
  height: 100%;
  transition: all 2s linear;
}

#test:hover {
  transform: scale(1.2);
}
<div id="wrapper">
  <img src="http://rack.3.mshcdn.com/media/ZgkyMDEzLzA1LzA4L2JlL2JhYmllc193aXRoLjA5NGNjLnBuZwpwCXRodW1iCTg1MHg1OTA-CmUJanBn/8f195417/e44/babies_with_swagg.jpg" id="test">
</div>
like image 45
Aaron K Avatar answered Jan 18 '23 22:01

Aaron K