Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Two divs: one fixed, other stretched

Tags:

html

css

I am trying to accomplish this: divs-fixed-and-stretched

But I am having trouble getting the two middle divs to play nice. If I set them both to a relative number (30% and 70%) it "works" but the left div changes size as the user changes the browser-windows width.

 #floatitleft{width:30%; float:left;}
 #floatitright{width:70%; float:left;}

What I want is, as the picture illustrates

 #floatitleft{width:300px; float:left;}
 #floatitright{width:100%; float:left;}

But this causes "floatitright" to end up beneath floatitleft. And if I set it to 70% it does end up to the right of "floatitleft" but as I change the browser size a little it ends up underneath yet again. What to do?

UPDATE: Eventually I ended up with:

#topper{
    height:100px;
    width:100%;
    background-color:blue;
}
#wrapperz{
    height:inherit;
    width:100%;
}
#wrapperz p{margin:0 0 0 0px; padding:10px 10px 0px 10px; color:#0F0F0F;}
#wrapperz #floatitleft{
    width:300px;
    float:left;
}
#wrapperz #floatitright{
    margin-left: 300px;
    min-width:300px;
}
#bottommer{
    height:100px;
    width:100%;
    background-color:red;
}

Which would be used as:

<div id="topper">
test
</div>

<div id="wrapperz">

<div id="floatitleft">
<p> Stuff </p>
</div>

<div id="floatitright">
<p> Stuff </p>
</div>

<div style="clear: both;"/>

</div> <!-- Close Wrapper -->

<div id="bottommer">
test
</div>

Note that this isn't proper HTML but it just serves as the solution to my example. Also, the "div style="clear: both" is escpecially important if you try this because not using that cuases the footer to mess up as the wrapper doesn't properly stretch vertically. But Mark has provided a what I believe to be better/cleaner alternative below.

like image 677
natli Avatar asked Sep 29 '11 15:09

natli


2 Answers

Wouldn't this work as intended?

#floatitleft{
    width:300px;
    float:left;
}
#floatitright{
    margin-left: 300px;
}
like image 170
ANeves Avatar answered Oct 22 '22 06:10

ANeves


Here, I made a duplicate of your picture: jsbin.com/ipexep/3 (click "edit in jsbin" at the top-right to view and edit the source)

I for the height of the top and bottom sections, I took the height for them that you put in the picture.

Note: I did it by making every section absolutely positioned and setting their top, bottom, left, or right attributes accordingly.

Also, notice that my method will match every screen size. I have streched it in every area you didn't specify a dimension. (except the header and footer needed a height dimension so I guessed since you didn't specify)

like image 42
Mark Kramer Avatar answered Oct 22 '22 06:10

Mark Kramer