Overflow hidden with border radius not working in chrome

戏子无情 提交于 2019-12-10 19:08:45

问题


Not sure whether it is chrome specific bug or what, but when I am transitioning child element on a parent that has overflow hidden with border radius, the overflow is visible, while the transition is in place.

var wrapper = document.getElementsByClassName('wrapper')[0],
  img = document.getElementsByTagName('img')[0];

/*
	Click anywhere in the bordered area to toggle img
*/

wrapper.addEventListener('click', function() {
  if (!img.className) {
    img.className = 'hidden';
  } else {
    img.className = '';
  }
}, false);
.wrapper {
  overflow: hidden;
  border-radius: 60px;
  border: 1px solid salmon;
}
img {
  width: 100%;
  height: auto;
  opacity: 1;
  transition: opacity 1s ease;
}
.hidden {
  opacity: 0;
}
<div class="wrapper">
  <img src="http://static.planetminecraft.com/files/resource_media/screenshot/1211/y-you-no-work_1687402.jpg">
</div>

Here's a fiddle demonstrating the issue https://jsfiddle.net/827vuyqb/2/

Any solutions, workarounds for this?


回答1:


Just position the wrapper element, and give it a z-index:

var wrapper = document.getElementsByClassName('wrapper')[0],
  img = document.getElementsByTagName('img')[0];

/*
	Click anywhere in the bordered area to toggle img
*/

wrapper.addEventListener('click', function() {
  if (!img.className) {
    img.className = 'hidden';
  } else {
    img.className = '';
  }
}, false);
.wrapper {
  overflow: hidden;
  border-radius: 60px;
  border: 1px solid salmon;
  
  /*Position and z-index*/
  position: relative;
  z-index: 1;
}
img {
  width: 100%;
  height: auto;
  opacity: 1;
  transition: opacity 1s ease;
}
.hidden {
  opacity: 0;
}
<div class="wrapper">
  <img src="http://static.planetminecraft.com/files/resource_media/screenshot/1211/y-you-no-work_1687402.jpg">
</div>


来源:https://stackoverflow.com/questions/40131314/overflow-hidden-with-border-radius-not-working-in-chrome

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!