I have this container with some text and an image inside it as last element, I am trying to set an ::after
to my container, however it is being shown over the image and not as the last element of the container:
I understand that I can't set a pseudo-selector to an <img/>
, but here I am setting ::after
to the container and I don't get why it isn't working properly.
Why is this happening and how could I make ::after
actually the last element of testDiv
?
P.S. I can't set the container or any parent element with position: relative
, since I need ::after
to have the same width as the screen and not just to fit inside the container and I don't have any element with the same width as the screen.
P.S. The margin-left:100px
is just to make it easier to be seen in the snippet, therefore it doesn't matter to my purpose.
.testDiv > div::after {
position: absolute;
height: 2px;
content: "";
background-color: red;
left: 0;
right: 0;
}
.testDiv > div {
margin-left: 100px;
}
<div class="testDiv">
<div>
<h1>TEST</h1>
<h2>TEST</h2>
<img src="https://www.acmetek.com/wp-content/uploads/rapidssl-logo.png" />
</div>
</div>