所以我试图用绝对位置定位我的伪元素,但相反,它的行为就像它的父元素是其他东西一样。
<!DOCTYPE html>
<html>
<head>
<style>
p::after {
content: " - Remember this";
position: absolute;
top: 0;
}
</style>
</head>
<body>
<div style="position: absolute; top: 50px; left: 50px; border: 1px solid
black;">
<p>My name is Donald</p>
<p>I live in Ducksburg</p>
<p><b>Note:</b> For this selector to work in IE8, a DOCTYPE must be declared,
and you must use the old, single-colon CSS2 syntax (:after instead of
::after).</p>
</div>
</body>
</html>
我从 w3school 得到了这个 + 一些编辑,因为我需要确定这不仅仅是我的 html 造成的。
我想要的是伪元素使用 p 标签作为其父元素而不是 div
最佳答案
位置为绝对的元素;相对于最近定位的祖先定位(而不是相对于视口(viewport)定位
p{
position:relative;
}
关于html -::之前和::之后绝对位置就像固定位置一样,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52133597/