I’m learning css and was struggling to understand why the html is rendering like so:
I can understand why the the red border is being cut off from the top and left. It’s because outlines don’t take up space since they’re drawn outside of the box: https://developer.mozilla.org/en/CSS/outline. In this example they’re being drawn outside of the <body> element.
-
However I was confused as to why border is being cut off from the
top. Any ideas? -
What css can be applied to the
<span>element to make the entire
outline and border display? -
Also, is it ever considered okay to place an inline element next to
a block element like<span>somestuff</span><div>somecontent</div>?
Point 1:
If you add a
float:leftor adisplay:block, the box will render correctly. This is because span is an inline element.Point 2:
Add the following:
Point 3:
You can place an inline element next to a block element as the design requires. You can also change the display style of the inline element by setting
display:blockordisplay:inline-blockor any of the other display values allowed.