So I read that <html>
and <body>
are block level elements, just like <div>
and <p>
.
I understand that block level elements start a new line.
For example aaa<div>b</div>ccc
looks like this:
aaa
b
ccc
So, why don't <html>
and <body>
add two lines to the top of your html page?
Block level elements don't "start new lines"... they simply expand to both sides indefinitely until the hit a container element or the sides of the display (width:100%
)... because of this, they have the effect of "pushing" any other content down below them, or dropping below any inline content that immediately precedes them. It also means that block-level elements will only "push down" sibling-level elements.
<html>
and <body>
elements have no siblings, only children, so they don't need to displace anything.
Here's a graphical representation of what's happening:
Given this markup:
<html>
<head></head>
<body>
<div> </div>
<div> </div>
<div style='width:45%; float:left;'>
<div> </div>
</div>
<div style='width:45%; float:left;'> </div>
</div>
</body>
</html>
Think of it this way:
<div>
<div>Text</div>
</div>
There is only one line of text:
Text
This is just like the case when you have any text in the body:
<html>
<body>Text</body>
</html>
When the text is in the child element, no new lines are introduced.
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