Forcing Right Div to fill space (Full Version)

All Forums >> [Web Development] >> Cascading Style Sheets



Message


BeTheBall -> Forcing Right Div to fill space (1/2/2008 12:45:21)

Happy New Year CSS gurus. I am having a little trouble with a fairly simple two-column layout. I want a fixed width for my left column and then want the right column to fill in the rest of the space. I have the two columns nested within another div set to 99% width. Problem is, when my content in the right div is narrow, the page does not fill in the entire remaining width. Here is the CSS:

.main_content {
	margin: 0 auto;
	width: 99%;
}

.sd_left {
	float:left;
	color: #000;
	margin: 0;
	padding: 0px 0px 0px 0px;
	width: 180px;
	font: 1.3em arial, helvetica, verdana, sans-serif;
}	

.sd_right {
 	background: #fff url(../images/back_white.jpg) repeat;
    clear: both;
    float: right;
	color: #000;
	margin: 0px;
	padding: 10px 0px 10px 10px;
	font: 1.2em arial, helvetica, verdana, sans-serif;
}	


Here is a screen capture of what I am getting on narrow pages.




Tailslide -> RE: Forcing Right Div to fill space (1/2/2008 15:11:05)

Well you could just float them both to the left which would possibly look neater - give less of a gap on the left.

If you're floating divs they must have a width too - which would cause a problem if you don't actually know what the width is with one div being fluid.

You might want to consider instead of having two divs floating next to each other, have the left div floating (with a fixed width) inside of the div containing the right-hand content which would take up the remaining space, whatever that is, minus a left margin of 180px.

Here's another way of doing it that looks pretty easy: http://css-tricks.com/examples/PerfectFluidWidthLayout/




BeTheBall -> RE: Forcing Right Div to fill space (1/2/2008 16:01:34)

Thanks Helena. I'll have a look at the example you sent. I found a work around, but it has me a bit uneasy. All I did was give my <h2> element a width of 100% and that seemed to fix my problem, however, like I said, not sure how comfortable I am with that "fix".




jaybee -> RE: Forcing Right Div to fill space (1/2/2008 17:55:17)

On my site I set up a container div then within that two columns of say 75% and 25%.

Floated one left with a clear, then the other floated right.

Both resize but if you want the smaller one to not get too narrow you could specify a min width or put a graphic in it which will force it to stay that width. Only needs to be 1 pixel high and whatever width you need.

If you're using graphics for buttons they'll do the same thing as long as they're not specified as backgrounds.




Page: [1]

Valid CSS!




Forum Software © ASPPlayground.NET Advanced Edition 2.4.5 ANSI
0.0625