I am trying to teach myself html and CSS through w3schools, and it mentions there that if no z-values are specified, elements that are positioned last in the html code will be shown on top. However, in their example, if we comment out the z-index of images so that none is specified, the image still shows up on top. Shouldn't the order from bottom to top be the heading, then the image, then the paragraph since this is the order in which they are specified in the code? Are their special overlapping rules being applied that I am not aware of?
P.S. I found this question, which references another instance of images appearing on top of text even though the text comes last in the html, but no reason is given for this behavior (instead, only the proper z-index code is recommended). However, I want to know why this is happening, rather than how to make the text come on top with z-index.
That's because the image is absolutely positioned. From the spec,
If you remove the
z-index
, the image is painted at step 6 in front of the paragraph at step 3 and the paragraph's text at step 5.