Firefox 中的视觉伪影,可能是由于 css-transform 或 ::after 元素造成的?
我试图给“卡片”元素一个看起来像是从页面上抬起的阴影。我使用 ::after 伪元素、css 变换和框阴影来完成此操作。
我使用的是 Mac OSX、Chrome(最新版本)和 Firefox 5。结果为
如您所知看,在 Firefox 渲染中有一个奇怪的类似边框的伪像。它的颜色似乎与主体背景颜色相关 - 正如您在第二个 Firefox 示例中看到的那样。
为此,我有以下代码:
HTML:
<div class="card_container">
<div class="card">
<!-- Content //-->
</div>
</div>
CSS:
.card{
padding: 5px;
background-color: #fff;
border: 1px solid #aaa;
height: 375px;
margin-bottom: 20px;
}
.card_container::after{
content: "";
width: 210px;
height: 10px;
-webkit-transform: rotate(2deg);
-moz-transform: rotate(2deg);
box-shadow: 3px 3px 3px #4a4a4a;
background-color: #4a4a4a;
position:absolute;
bottom: 20px;
right: 8px;
z-index: -1;
}
周围还有更多 CSS,但我相当确定我已经尝试了足够多的内容来排除其他任何情况。
任何想法为什么会发生这种情况,如果它是特定于平台/浏览器的,和/或任何修复?感谢您的帮助!
I'm attempting to give a 'card' element a drop-shadow which looks like it is lifted from the page. I'm doing this with the ::after pseudo-element, a css-transform, and a box shadow.
I'm using Mac OSX, Chrome (latest version) and Firefox 5. The results are
As you can see, there is a strange border-like artifact in the firefox rendering. The color of this seems to be linked to the body background color - as you can see in the second firefox example.
To do this I have the following code:
HTML:
<div class="card_container">
<div class="card">
<!-- Content //-->
</div>
</div>
CSS:
.card{
padding: 5px;
background-color: #fff;
border: 1px solid #aaa;
height: 375px;
margin-bottom: 20px;
}
.card_container::after{
content: "";
width: 210px;
height: 10px;
-webkit-transform: rotate(2deg);
-moz-transform: rotate(2deg);
box-shadow: 3px 3px 3px #4a4a4a;
background-color: #4a4a4a;
position:absolute;
bottom: 20px;
right: 8px;
z-index: -1;
}
There's some more CSS around, but I'm fairly sure I've played around enough to rule anything else out.
Any ideas why this is happening, if it's platform/browser specific, and/or any fix? Thanks for any help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
:after
是一个棘手的选择器:您将 HTML 元素添加到文档中,但无法自由操纵其位置。我建议像这样更改 HTML:您必须向正在使用的每个卡片元素添加一些“shadow”div,这可能需要一些时间。
现在来说一下 CSS:
这个解决方案不是很灵活:如果更改卡片的宽度,则需要调整阴影元素(例如,阴影越宽,旋转越少)。
:after
is a tricky selector: you add an HTML element to your document, but you cannot manipulate its position freely. I suggest changing the HTML like this:You have to add some the "shadow" div to every card elements in use, which might take some time.
Now for the CSS:
This solution is not very flexible: you will need to adjust the shadow element if you change the card's width (the wider the shadow, the less rotation, for instance).