Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There are a few ways of achieving what you're trying to achieve. Most commonly, using <code>display: table</code>, <code>display: table-cell</code>, etc isn't very high on the list.</p> <p>So, here's how I would do it: <a href="http://jsfiddle.net/VKnQZ/1/" rel="nofollow">http://jsfiddle.net/VKnQZ/1/</a></p> <p>Do bear in mind that I don't know the full circumstance of what you're attempting so it may well be that I'm missing a (valid) reason that you're using table display properties in the first place.</p> <p>You'll notice a few things here:</p> <ul> <li>I've done away with your table display properties. I don't think you need them, and <a href="http://alistapart.com/article/css-floats-101" rel="nofollow">floats</a> do the job just fine (just remember to clear them).</li> <li>I've removed your <code>display</code> from the cell divs. As someone in the comments above pointed out, divs inherit <code>display: bloc</code>k by default. The additional dimensions set their size as you already had it.</li> <li>I'm using the <a href="http://www.w3.org/TR/CSS2/selector.html" rel="nofollow"><code>+</code> selector</a> to put in the spacing between elements. In this instance <code>div + div</code> is essentially short-hand for 'every div which is beside another div' - so all of them aside from the first.</li> </ul> <p>Hopefully that achieves what you're aiming for and does away with all the nasty hacky overflow/margins/etc.</p> <p>Here's the code:</p> <p><strong>HTML (only change is to remove the row div):</strong></p> <pre><code>&lt;div id="nav"&gt; &lt;div class="red"&gt;&lt;/div&gt; &lt;div class="green"&gt;&lt;/div&gt; &lt;div class="blue"&gt;&lt;/div&gt; &lt;/div&gt; </code></pre> <p><strong>CSS:</strong></p> <pre><code>body { padding: 0; margin: 0; } #nav { float: right; } #nav div { float: left; width: 120px; height: 40px; } #nav div + div{ margin-left: 10px; } .red { background-color:#f00 } .green { background-color:#0f0 } .blue { background-color:#00f } </code></pre>
    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