Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This is a common issue when working with floats. There are several common solutions, which I have ordered by personal preference (best approach first):</p> <ol> <li><p>Use the ::after CSS pseudo element. This is know as the 'clearfix', and works IE8 and up. If you need compatibility with earlier versions of IE, <a href="https://stackoverflow.com/questions/211383/which-method-of-clearfix-is-best">this answer should help</a>. <a href="http://jsfiddle.net/dX2Xh/74/" rel="nofollow noreferrer">Example</a>.</p> <pre><code>.parentelement::after { content: ""; display: table; clear: both; } </code></pre></li> <li><p>Add the two floats into a container with the CSS attribute <code>overflow: auto</code> or <code>overflow: hidden</code>. However, this approach can cause issues (e.g. when a tooltip overlaps the edges of the parent element a scrollbar will appear). <a href="http://jsfiddle.net/dX2Xh/1/" rel="nofollow noreferrer">Example</a>.</p> <pre><code>&lt;div style="overflow: auto"&gt; &lt;div style="float: left"&gt;&lt;/div&gt; &lt;div style="float: left"&gt;&lt;/div&gt; &lt;/div&gt; </code></pre></li> <li><p>Add a set height to the parent element. <a href="http://jsfiddle.net/dX2Xh/4/" rel="nofollow noreferrer">Example</a>.</p> <pre><code>&lt;div style="height: 200px"&gt; &lt;div style="float: left"&gt;&lt;/div&gt; &lt;div style="float: left"&gt;&lt;/div&gt; &lt;/div&gt; </code></pre></li> <li><p>Make the parent element a float. <a href="http://jsfiddle.net/dX2Xh/2/" rel="nofollow noreferrer">Example</a>.</p> <pre><code>&lt;div style="float: left"&gt; &lt;div style="float: left"&gt;&lt;/div&gt; &lt;div style="float: left"&gt;&lt;/div&gt; &lt;/div&gt; </code></pre></li> <li><p>Add a div after the floats with <code>clear: both</code>. <a href="http://jsfiddle.net/dX2Xh/" rel="nofollow noreferrer">Example</a>.</p> <pre><code>&lt;div style="float: left"&gt;&lt;/div&gt; &lt;div style="float: left"&gt;&lt;/div&gt; &lt;div style="clear: both"&gt;&lt;/div&gt; </code></pre></li> </ol>
    singulars
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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