As I understand, ::before
pseudo shall create a node as a first child of the element it belongs to. I am trying to add ::before
element that shall be underneath the main element, but it renders above it, overlapping the main content. As I understand, it shall be rendered like:
<div id="c">
<div id="pseudo-before">
</div>
Main text
</div>
And, if I need to place ::before
pseudo under the main content, I just have to set the z-index for the parent and child respectively. I tried to set it but it does not work. I suppose I do not understand something about how it works, please help - how to make ::before
or ::after
to be shown under the content of the element they belongs to?
Thank you
An explanation (as requested): I need the red box o the snippet to be placed beneath the green box but above the containing div and body, and I cannot do that. Please tell me how to do that.
#c
{
position: absolute;
top: 1em;
left: 1em;
width: 20em;
text-align: justify;
border: 1px solid #000;
background: #0f0;
padding: 1em;
width: 20em;
display: inline-block;
font-family: helvetica, arial, sans-serif;
z-index: 100;
}
#c::before
{
content: "";
position: absolute;
top: 1em;
bottom: -1em;
width: 5em;
background: rgba(255,0,0,.5);
z-index: 0;
}
<div id="b">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Scelerisque in dictum non consectetur a. Non diam phasellus vestibulum lorem sed risus. Id diam maecenas ultricies mi eget mauris pharetra et. Aliquam nulla facilisi cras fermentum odio eu. Urna neque viverra justo nec ultrices dui. Eget aliquet nibh praesent tristique magna sit. Diam in arcu cursus euismod quis. Justo eget magna fermentum iaculis. Ipsum nunc aliquet bibendum enim. Arcu risus quis varius quam quisque id diam vel quam. Porta nibh venenatis cras sed felis eget velit aliquet. Odio ut enim blandit volutpat maecenas volutpat. Ut placerat orci nulla pellentesque dignissim enim sit. Aliquet sagittis id consectetur purus. Vulputate sapien nec sagittis aliquam. Pellentesque elit eget gravida cum sociis natoque penatibus et magnis. Facilisis mauris sit amet massa vitae tortor condimentum. Porttitor massa id neque aliquam vestibulum morbi.
<div id="c">
It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English.
</div>
</div>