Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I'm afraid that there is no way to satisfy <em>all</em> your constraints. The main things that don't seem to have a CSS solution are:</p> <ul> <li>Controlling the width of just the green bit can't be done without affecting the width of the red <code>:before</code> and blue <code>:after</code> content. As you mention in the comments to the question, using a different DOM structure is not an option.</li> <li>The blue (<code>:after</code>) content should take up all space not needed by the green (main) content. </li> <li>The fixed height of red/blue may require some clearing on the elements below the entire div.</li> </ul> <p>So, as far as I could tell, the question as you asked it doesn't have a 100% satisfying answer. Either way, here's the code I came up with researching this problem, perhaps it can help you or others stumbling on this question. See either <a href="http://jsfiddle.net/pLZDH/" rel="nofollow">this jsfiddle</a> or the code below:</p> <pre><code>&lt;div id="page"&gt; &lt;div class="green"&gt; &lt;span&gt;Orange 1.&lt;/span&gt; &lt;span&gt;Orange 2. Which can be really wide.&lt;/span&gt; &lt;/div&gt; &lt;p style="clear: both;"&gt;Black is the page. Clearing is needed because the red and blue boxes are not in the flow but do have quite some height.&lt;/p&gt; &lt;/div&gt; </code></pre> <p>CSS: </p> <pre><code>div#page { border: 2px solid black; width: 80%; padding: 2px; } div.green:before { content: 'red / before'; border: 2px solid red; float: left; display: inline-block; width: 140px; height: 200px; } div.green { border: 2px solid green; } div.green:after { content: 'blue / after'; border: 2px solid blue; display: inline-block; float: right; height: 60px; } div.green span { border: 2px solid orange; } </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. VO
      singulars
      1. This table or related slice is empty.
    2. 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