views:

57

answers:

5

Suppose I have an HTML page with three blocks of fixed width (their height can vary if that's important), like shown on picture: alt text

I would like to make it behave as shown on next picture: when browser screen width is reduced so it can't fit all three blocks in one line, first block goes down. alt text

Is it possible to achieve such behavior? Preferably with CSS only but any working solution would be great.

A: 

Use divs with float:left and fixed width values

        <div style="float:right; width:250px; position:relative; height:100px; border:solid 1px #000000">    
3
    </div>        
        <div style="float:right; width:250px; position:relative; height:100px; border:solid 1px #000000">
        2    
    </div>
<div style="float:right; width:250px; position:relative; height:100px; border:solid 1px #000000">    
        1
    </div>

like so... I am aware that the 1st one will go right but this is the simplest i can do without getting into javascript..

Sevki
That would make block 3 drop to the next line, not block 1
Tim Goodman
Re Revision: This *would* make block 1 drop, but not in the way the OP requested. Block 1 would float to the right, not the left.
deceze
@deceze: Yeah, I'd thought about using `float:right` myself and rejected it for just that reason. Like you, I don't really see any obvious way to do this with CSS alone, so I'm unfortunately reduced to pointing out flaws in other people's answers.
Tim Goodman
A: 

Put all these three blocks inside a div and set it's width to 100%, when the screen will resize the blocks will be arranged automatically.

Ravia
+2  A: 

It's virtually impossible to let the first block drop down without any Javascript trickery. Making the right-most one drop with float: left is easy on the other hand.

deceze
+1 for being the only answer thus-far that caught the fact that block 1 was supposed to drop
Tim Goodman
I just wish I had a better answer to provide, but this seems to call for a lot of custom Javascripting.
deceze
A: 
<div style="width: 100%;">
  <div style="width: 50px; float left;">DIV1</div>
  <div style="width: 50px; float left;">DIV2</div>
  <div style="width: 50px; float left;">DIV3</div>
  <br style="clear: left;" />
</div>
Dustin Laine
That would make block 3 drop to the next line, not block 1
Tim Goodman
+2  A: 
<div style="width: 100%;">
    <div style="display: inline-block; background-color: red; width: 200px;">DIV2</div>
    <div style="display: inline-block; background-color: yellow; width: 200px;">DIV3</div>
    <div style="display: inline-block; float: left; background-color: lightBlue; width: 200px;">DIV1</div>
    <br style="clear: left;">
</div>

This one works. You put block 1 as the last one and only make that one float left.

ZippyV
Thanks, this looks like exactly what I need. Puts first block on bottom by default in Opera 10.10 while working fine in all other browsers which is quite acceptable.
Anton
Nice one, although it only works consistently for the first block and is hardly compatible with IE.
deceze
@deceze: Just checked it, in IE all the blocks are indeed positioned in a single row. But still I suppose this works for me since blocks 2 and 3 can be wrapped in a single DIV thus making them to be positioned inline.
Anton