类似于 :before
和 :after
CSS 伪类,我们是否有任何 :below
和 :above
伪类来模拟相应的效果?
类似于 :before
和 :after
CSS 伪类,我们是否有任何 :below
和 :above
伪类来模拟相应的效果?
:before
和 :after
伪类将 伪元素 创建为目标元素的子元素。在 DOM 中,父/子是唯一的物理位置概念,视觉位置是样式问题。.a {
margin-top: 20px;
}
.a::before,
.a::after {
display: block; /* they are inline by default */
}
.a::before {
content: "above";
color: blue;
top: -1em; /* go above */
}
.a::after {
content: "bellow";
color: red;
top: 1em; /* go bellow */
}
<div class="a">target</div>
.a
应用了relative
定位,对其伪元素应用了absolute
定位一样,我无法将我的顶级/父元素设置为relative
。你有什么办法解决这个问题吗? - sherlock