Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <h1>Beware <code>float: left</code>… </h1> <h2>…there are many ways to align elements side-by-side.</h2> <p>Below are the most common ways to achieve two elements side-by-side…</p> <h1>Demo: <a href="https://codepen.io/beau/pen/odbrRa" rel="noreferrer">View/edit all the below examples on Codepen</a></h1> <hr> <h1>Basic styles for all examples below…</h1> <p>Some basic css styles for <code>parent</code> and <code>child</code> elements in these examples: </p> <pre><code>.parent { background: mediumpurple; padding: 1rem; } .child { border: 1px solid indigo; padding: 1rem; } </code></pre> <hr> <p><a href="https://i.stack.imgur.com/zCZNA.png" rel="noreferrer"><img src="https://i.stack.imgur.com/zCZNA.png" alt="float:left"></a></p> <p>Using the <code>float</code> solution my have unintended affect on other elements. (Hint: You may need to use a <a href="https://stackoverflow.com/a/1633170/101290">clearfix</a>.)</p> <p>html</p> <pre><code>&lt;div class='parent'&gt; &lt;div class='child float-left-child'&gt;A&lt;/div&gt; &lt;div class='child float-left-child'&gt;B&lt;/div&gt; &lt;/div&gt; </code></pre> <p>css</p> <pre><code>.float-left-child { float: left; } </code></pre> <hr> <p><a href="https://i.stack.imgur.com/ZkYMO.png" rel="noreferrer"><img src="https://i.stack.imgur.com/ZkYMO.png" alt="display:inline-block"></a></p> <p>html</p> <pre><code>&lt;div class='parent'&gt; &lt;div class='child inline-block-child'&gt;A&lt;/div&gt; &lt;div class='child inline-block-child'&gt;B&lt;/div&gt; &lt;/div&gt; </code></pre> <p>css</p> <pre><code>.inline-block-child { display: inline-block; } </code></pre> <hr> <p><strong>Note</strong>: the space between these two child elements can be removed, by removing the space between the div tags: </p> <p><a href="https://i.stack.imgur.com/bRG0n.png" rel="noreferrer"><img src="https://i.stack.imgur.com/bRG0n.png" alt="display:inline-block (no space)"></a></p> <p>html</p> <pre><code>&lt;div class='parent'&gt; &lt;div class='child inline-block-child'&gt;A&lt;/div&gt;&lt;div class='child inline-block-child'&gt;B&lt;/div&gt; &lt;/div&gt; </code></pre> <p>css</p> <pre><code>.inline-block-child { display: inline-block; } </code></pre> <hr> <p><a href="https://i.stack.imgur.com/yvSFz.png" rel="noreferrer"><img src="https://i.stack.imgur.com/yvSFz.png" alt="display:flex"></a></p> <p>html</p> <pre><code>&lt;div class='parent flex-parent'&gt; &lt;div class='child flex-child'&gt;A&lt;/div&gt; &lt;div class='child flex-child'&gt;B&lt;/div&gt; &lt;/div&gt; </code></pre> <p>css</p> <pre><code>.flex-parent { display: flex; } .flex-child { flex: 1; } </code></pre> <hr> <p><a href="https://i.stack.imgur.com/WdIk4.png" rel="noreferrer"><img src="https://i.stack.imgur.com/WdIk4.png" alt="display:inline-flex"></a></p> <p>html</p> <pre><code>&lt;div class='parent inline-flex-parent'&gt; &lt;div class='child'&gt;A&lt;/div&gt; &lt;div class='child'&gt;B&lt;/div&gt; &lt;/div&gt; </code></pre> <p>css</p> <pre><code>.inline-flex-parent { display: inline-flex; } </code></pre> <hr>
    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. 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