我发誓我已经做了这一百次,但对于我的生活,我不明白为什么我的:before
伪元素的背景是在文字后面显示,但不在主播背景的后面。思考?::负Z指数伪元素之前不显示在父母后面
.button {
background: tomato;
padding: 10px 30px;
margin: 20px 0;
display: inline-block;
}
.button:hover {
margin: 18px 0 22px 2px;
position: relative;
z-index: 2;
}
.button:hover:after {
position: absolute;
background: red;
top:-2px;
left: -2px;
content: "";
z-index: -10;
width: 100%;
height: 100%;
}
<a class="button" href="#">Meow</a>
样品在这里:http://jsfiddle.net/cfree/hnKLr/
这在Chrome的新版本中变得更加清晰,其中:: before和:: after是它们所连接的元素内的节点。 – cfree