Using this HTML, I can't figure why the text displays behind the image:
<div style="position: relative">
<img src="image_url_here" style="position:absolute; top: 10px; left: 10px;" />
This is some text, drawn on the page after the image, why is it drawn behind the image?
</div>
?
Tested in Chrome on Mac & PC and IE on PC.
This article can answer your question: z-index explained
TL;DR: Positioned elements are stacked over non-positioned elements, so just add position: relative
to the text you want stacked on top.
<div style="position: relative">
<img src="https://via.placeholder.com/150" style="position:absolute; left: 10px;" />
<span style="position:relative">This is some text</span>
</div>
Refer this https://developer.mozilla.org/en-US/docs/Web/CSS/position
Try this or set as per your requirement
<div style="position: relative">
<img src="image_url_here" style="position:relative; top: 10px; left: 10px;" />
This is some text, drawn on the page after the image, why is it drawn behind the image?
</div>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With