Span padding

Why the words that come before the span is covered by the span padding and background here is the word "paragraph" is covered but the words that comes after the span is not covered by the span padding and background and appears over it?
No description
9 Replies
ᴋʙ
ᴋʙ4mo ago
😮 never seen that before lol
Kevin Powell
Kevin Powell4mo ago
spans are an inline element, so things like height/width don't work (or margin top and bottom), and padding is only visual. As for why it's below that text, but above the other text, it's because that text comes later, so it's "higher". Layering in CSS tends to work that way, unless you add z-index into the picture.
Mustafa_Elghisha
Mustafa_ElghishaOP4mo ago
But I'm not using any position properties so why the z-index comes into play or how does this layering works I don't fully get it
Kevin Powell
Kevin Powell4mo ago
everything the browser renders has to be layered in some way. If you aren't using z-index in any way, earlier elements are always "below" later elements. When you make a span, the text before and after that span get wrapped in an anonymous box, and the same rules apply. The box before the span is below the span, the box after the span is layered above it. Normally we don't see any of this layering, because elements don't tend to overlap, but when they do, if we haven't used z-index, the later things are always on top of earlier things. (also, don't worry about what an anonymous box is)
Mustafa_Elghisha
Mustafa_ElghishaOP4mo ago
Well now that does make sense, thanks alot Kevin❤️ ❤️
ᴋʙ
ᴋʙ4mo ago
Wait that actually makes so much sense, its just like how rendering using the canvas API the last code always renders above the previous geometries.
No description
ᴋʙ
ᴋʙ4mo ago
No description
ᴋʙ
ᴋʙ4mo ago
Never thought that much about it.. 😄
Mustafa_Elghisha
Mustafa_ElghishaOP4mo ago
I guess there will always be something new to learn in CSS:thumbup:

Did you find this page helpful?