在div上使用百分比transformY可能会导致相邻div之间出现接缝
我一直在使用 CSS3 转换在我的网站中创建一个弹出窗口,但我注意到该弹出窗口中相邻 div 之间存在接缝。
我做了一个最小的例子来演示。
#wrapper {
width: 50px;
transform: translateY(50%);
}
#a,
#b {
background: red;
}
#a {
height: 50px;
width: 100px;
}
#b {
height: 51px;
width: 150px;
}
<div id="wrapper">
<div id="a">
</div>
<div id="b">
</div>
</div>
您可以看到 #a 和 #b 之间有一个接缝。
我深入研究了这个问题,发现在 chrome 中使用具有一定高度的百分比变换Y可能会导致这个问题(我没有在 Firefox 中测试它)。
在我的示例中,如果 #wrapper 的高度是奇数,translateY(50%) 将在子元素中创建接缝。
你可以尝试将 #b 的高度设置为 52px,你会看到接缝消失。
在我的网站中,我通过为该弹出窗口设置固定高度来修复它,但有时你无法控制高度,我想知道这是否是 chrome 中的错误,或者我没有做对。
抱歉我的英语不好。
I've been using CSS3 transform to create a popup in my website, but I noticed there's a seam between adjacent divs in that popup.
I made a minimal example to demonstrate.
#wrapper {
width: 50px;
transform: translateY(50%);
}
#a,
#b {
background: red;
}
#a {
height: 50px;
width: 100px;
}
#b {
height: 51px;
width: 150px;
}
<div id="wrapper">
<div id="a">
</div>
<div id="b">
</div>
</div>
You can see there's a seam between #a and #b.
I've digged into that problem and found out using percentag transformY with some certain height may cause this problem in chrome(I didn't tested it in firefox).
In my example, if the #wrapper's height is an odd number, translateY(50%) will create a seam in child elements.
You can try to set #b's height to 52px and you'll see that seam disappear.
In my website I fixed it by setting a fixed height for that popup, but sometimes you just can't control height, I want to know if this is a bug in chrome or I didn't make it right.
Sorry for my bad English.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
添加
Backface-visibily:hidden;
<代码> #wrapper 。那将完成这项工作。Add
backface-visibility: hidden;
to#wrapper
. that will do the job.