:: before和:: after位置绝对作用类似于位置固定 [英] ::before and ::after position absolute acting like position fixed
本文介绍了:: before和:: after位置绝对作用类似于位置固定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
所以我试图将伪元素放置在绝对位置,但是它的行为就像它的父元素是其他东西一样.
So I am trying to position my pseudo element with position absolute, but instead, it is acting like its parent is something else.
<!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.
i got that from w3school + some editing, because I needed to be sure it wasn't just my html that caused this.
我想要的是让伪元素使用p标签作为其父元素而不是div
what i want is for the pseudo elements to use the p tag as their parent and not the div
推荐答案
位置为:绝对;相对于最近的祖先(而不是相对于视口
An element with position: absolute; is positioned relative to the nearest positioned ancestor (instead of positioned relative to the viewport
p{
position:relative;
}
这篇关于:: before和:: after位置绝对作用类似于位置固定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文