I am experimenting with pseudo elements and i am wondering why the .container::after
element is changing its position during the animation. Here is the HTML and the CSS code:
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
height: 100vh;
}
header {
position: sticky;
top: 0;
display: flex;
justify-content: center;
align-items: center;
padding: 0.3rem;
background-color: steelblue;
z-index: 1;
}
main {
display: flex;
flex-flow: column nowrap;
justify-content: center;
align-items: center;
font-size: 2rem;
background-color: grey;
height: 100%;
position: relative;
}
div {
border: 10px solid red;
background-color: white;
}
main:hover .container {
transform: rotate(360deg);
color: purple;
transition: all 2s;
}
main .container::after {
position: absolute;
top: 200px;
left: 100px;
background-color: white;
color: gold;
content: "after div";
}
<header>
<h1>stuff</h1>
</header>
<main>
<div class="container">I am a container</div>
</main>
I tried to put the
position: relative
on the div element. But this is not what i want. Obviously the ::after element gets related to its parent element (div) during the animation but why is that? Can i avoid that?