Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing CSS display:inline-block or float:left with mixed amounts of text
    primarykey
    data
    text
    <p>Looking for some expert advice here about how best to style the following HTML:</p> <pre><code>&lt;body&gt; -Some content- &lt;div class="parent" style="height:50%;"&gt; &lt;div class="child" style="background-color:#FF9999;"&gt;An image&lt;/div&gt; &lt;div class="child" style="background-color:#9999FF;"&gt;Some text&lt;/div&gt; &lt;/div&gt; &lt;/body&gt; </code></pre> <p>To obtain a result that behaves like this:</p> <p><img src="https://i.stack.imgur.com/kuJry.png" alt="enter image description here"></p> <p>The criteria that I am working with are the following:</p> <ul> <li>The container div, .parent, is a block element and fills the entire width of the browser window.</li> <li>I know the width of the first/left inner div, in pixels but not as a percentage, based on the regularity of the images that will go there.</li> <li>I don't know the width of the second/right inner div - as it contains a variable amount of text that should automatically fill the entire space to the right, regardless of browser window width</li> <li>The height of the first/left div, when shorter than the second/right div, should stretch to the same height (here's the reason: the first/left div will have a right-border to set it off from the second/right div, and this border should be the height of the .parent div; however, the first/left div is not always present in the mark-up, in which case the border should not appear).</li> <li>I cannot use JavaScript trickery.</li> </ul> <p>Solutions I have tried based on my experience and help from web sources:</p> <ol> <li><p>Float: The traditional method that uses float:left leaves me apparently unable to stretch the first/left div to the (variable) height of either its sibling or .parent.</p></li> <li><p>Inline-block: .parent {background-color:#999999;} .parent > .child {display:inline-block;vertical-align:top;height:100%;}</p></li> </ol> <p>Using display:inline-block appears to work like a charm when the text in the second/right div is not enough to fill an entire line. The moment there is more text, however, the second/right div grows as wide as the outer container will let it, forcing it to wrap under the first/right div.</p> <p>Any insights would be much appreciated!</p>
    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.
    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