Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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>

i got that from w3school + some editing, because I needed to be sure it wasn't just my html that caused this.

what i want is for the pseudo elements to use the p tag as their parent and not the div

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
482 views
Welcome To Ask or Share your Answers For Others

1 Answer

An element with position: absolute; is positioned relative to the nearest positioned ancestor (instead of positioned relative to the viewport

w3schools example here

My Example here

  p{
       position:relative;
  }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...