Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>When you set <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/display" rel="nofollow noreferrer"><code>display: inline-block;</code></a> to an element, the element will be flowed with surrounding content.</p> <p>So you would need to add a line-break <code>&lt;br&gt;</code> to produce a line break in text, but the vertical space of the line will remains as <a href="https://stackoverflow.com/a/18378962/1725764">you mentioned</a>. <em>[and one more thing happens is the horizontal scroll-bar which will appear <a href="http://jsbin.com/eGug/6/edit" rel="nofollow noreferrer">if you decrease the width of the panel</a>.]</em></p> <h2>Introduction</h2> <p>Using <code>&lt;table&gt;&lt;/table&gt;</code> element has a lot of benefits here.</p> <p>When you use <code>&lt;table&gt;</code> element <em>(as the following)</em>, it causes the content goes to the next line. And when the remain horizontal space gets lower than width of the <code>&lt;table&gt;</code>, it'll go to the next line and push the content down.</p> <p>And also, horizontally scroll-bar won't appear in this case, because browsers won't display the <code>&lt;table&gt;</code> when it hasn't any element inside or any specific <code>height</code> or <code>border</code> properties.</p> <p><em>(different browsers have different behavior, Mozilla Firefox doesn't display <code>table</code> element with a specific <code>border</code> property but Google Chrome does.)</em></p> <p><strong>HTML:</strong></p> <pre class="lang-html prettyprint-override"><code>&lt;img src="http://placehold.it/100x50" alt=""&gt; &lt;table&gt;&lt;/table&gt; Lorem ipsum dolor sit amet... </code></pre> <p><strong>CSS:</strong></p> <pre class="lang-html prettyprint-override"><code>img { float: left; } table { width: 12em; } </code></pre> <p>Here is the <strong><a href="http://jsbin.com/eGug/9/edit" rel="nofollow noreferrer">JSBin Demo</a></strong>.</p> <h2>The Solution</h2> <p>As a pure CSS way, I used <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/::before" rel="nofollow noreferrer"><code>::before</code></a> pseudo-element to create a element which behaves like the <code>&lt;table&gt;</code> HTML element.</p> <p><strong>HTML:</strong></p> <pre class="lang-html prettyprint-override"><code>&lt;div&gt; &lt;img src="http://placehold.it/400x400" alt=""&gt; &lt;p class="content"&gt; &lt;!-- Here is the content... --&gt; &lt;/p&gt; &lt;/div&gt; </code></pre> <p><strong>CSS:</strong></p> <pre class="lang-css prettyprint-override"><code>img { float: left; } .content:before { content: ' '; display: table; width: 10em; /* &lt;-- Change the current width size */ } </code></pre> <p>Here is the <strong><a href="http://jsbin.com/EJeVUrE/1/edit" rel="nofollow noreferrer">JSBin demo</a></strong>.</p>
    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.
    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