html - Do block elements ignore floating elements? -


w3c states that:

since float not in flow, non-positioned block boxes created before , after float box flow vertically if float did not exist. however, current , subsequent line boxes created next float shortened necessary make room margin box of float.

this work expected divs:

#a  {  	width: 100px;  	height: 100px;  	background-color: blue;  	float: left;  }    #b  {  	width: 200px;  	height: 200px;  	display: block;  	border: 1px solid black;  	background-color: red;  }
<body>  	<div id=a></div>  	  	<div id=b></div>  </body>
here red div block-level element, therefore it's ignoring floating one. (if changed red 1 display: inline-block appear next floating one)

but, if apply display: block image ,it won't ignore floating div, why?

#a  {  	width: 100px;  	height: 100px;  	background-color: blue;  	float: left;  }    #b  {  	width: 200px;  	height: 200px;  	display: block;  	border: 1px solid black;  }
<body>  	<div id=a></div>  	  	<img id=b src="https://www.gravatar.com/avatar/5cb44dcd4ebddfea3ede8c6d46b02795?s=328&d=identicon&r=pg&f=1">  </body>

several paragraphs after 1 quote, spec says:

the border box of table, block-level replaced element, or element in normal flow establishes new block formatting context (such element 'overflow' other 'visible') must not overlap margin box of floats in same block formatting context element itself.

although you've applied display: block image, being image it's replaced element, , therefore float cannot intrude bounds.

only non-replaced block boxes don't establish block formatting contexts , in same flow float may ignore float.1 block-level replaced element not block box, because replaced element cannot block container box.2


1 you're thinking, that's ridiculously specific statement, , is. it's why terms "block element" considered extremely vague in css parlance. again, doesn't css defines equally vague terms "block box" refer boxes both block-level boxes , block container boxes.

2 this imply "non-replaced block box" of tautology, reinforces how ridiculously specific statement is.


Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -