Note that there are some explanatory texts on larger screens.

plurals
  1. POFloats and Margin Collapse
    primarykey
    data
    text
    <p>so I'm having a hard time understanding the circumstances under which a float can have margins collapse through it and how that affects the position of the float. I've included a page that seems to show two different behaviors in the same page.</p> <p>The red float seems to be positioned before the margins that collapsed through it, whereas the blue ones down below seem to have the margins collapse through them and then be positioned after those margins have collapsed.</p> <p>Any help would be much appreciated.</p> <p>Cheers, Ben</p> <pre><code>&lt;html xmlns="http://www.w3.org/1999/xhtml"&gt; &lt;head&gt; &lt;title&gt;Inheritance Tests&lt;/title&gt; &lt;style&gt; * { margin: 0px ; padding: 0px ; font-family: courier ; font-size: small ; } .test4 {width: 200px; height: 100px; border-style: solid; border-width: 1px;} .test5 {border: 1px solid red; width: 200px; height: 50px; float: left; } .floatedRect { width: 50px ; height: 50px ; float: left ; background-color: #9cf ; } .text { margin: 10px ; } &lt;/style&gt; &lt;/head&gt; &lt;body&gt; &lt;div class="test4"&gt; Normal Flow &lt;/div&gt; &lt;div class="test5"&gt; Floated &lt;/div&gt; &lt;div style="margin-top: 100px"&gt; Has a top margin &lt;/div&gt; &lt;div style="clear: both"&gt; &lt;div class="floatedRect"&gt;&lt;/div&gt; &lt;div class="text"&gt;some text&lt;/div&gt; &lt;div class="floatedRect"&gt;&lt;/div&gt; &lt;div class="text"&gt;some text&lt;/div&gt; &lt;div class="floatedRect"&gt;&lt;/div&gt; &lt;div class="text"&gt;some text&lt;/div&gt; &lt;/div&gt; &lt;/body&gt; &lt;/html&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload