Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>CSS columns seem like a promising solution at first, but they won't automatically adjust the width of the container as areas are added or removed.</p> <p>My suggestion is to lay out the divs as if you were stacking them horizontally rather than vertically, going from right to left. That is easy enough to achieve with <code>float:right</code>. Once you have that, you can rotate the whole container 90 degrees to get the equivalent vertical layout. But since the area divs will now all be incorrectly oriented, you'll also need to rotate those 90 degrees back in the opposite direction.</p> <p>Something like this:</p> <pre><code>#container { position:relative; background-color:red; max-width:500px; margin-left:-500px; max-height:500px; overflow:hidden; -webkit-transform:rotate(-90deg); -webkit-transform-origin:top right; -ms-transform:rotate(-90deg); -ms-transform-origin:top right; transform:rotate(-90deg); transform-origin:top right; padding:20px 0 0 20px; -webkit-box-sizing:border-box; -moz-box-sizing:border-box; box-sizing:border-box; } #area { background-color:yellow; margin:0 20px 20px 0; width:100px; height:100px; float:right; -webkit-transform:rotate(90deg); -ms-transform:rotate(90deg); transform:rotate(90deg); } </code></pre> <p><a href="http://jsfiddle.net/xJMEs/" rel="nofollow">Fiddle example</a></p> <p>Note the negative <code>margin-left</code> on the container, which adjusts the position after rotation - that needs to match the container "height" (i.e. the <code>max-width</code> property). The <code>max-height</code> property represents the maximum "width" that the container will reach before being clipped. The <code>overflow:hidden</code> is needed to force the container to grow to contain its floating child elements.</p> <p>Also, note that because the area divs are now floated, the margins between them won't collapse. One way of solving that is to restrict the margins to only two sides (I've used right and bottom) and then emulate the margins for the other sides via padding on the container with <code>box-sizing:border-box</code>.</p> <p>Finally, in this particular example the area divs have a 1:1 aspect ratio, which means we don't have to worry about repositioning them after the rotation. Things become slightly more complicated if their width and height are different.</p> <p>This solution won't work on older versions of IE, but it at least supports IE9.</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. 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