CSS Height Problems

Status
Not open for further replies.

Stray Toaster

Ars Tribunus Militum
2,292
Subscriptor++
I have a page that is not displaying height correctly.

I have the body, html and everything else set to height: 100%; but when I look at the page, the height is getting stopped at the bottom of the browser window, and if I scroll down the div background are not continuing down.

One of my div's has content the extend below the base, and if I scroll that content is their, but if I inspect the element with firebug it tells me the height is on as tall as the browser window, in my current case '568' when it should be closer to 800px...

I'm not really sure what is broken or not working. The HTML has been validated, no issues. Here is the CSS in question:
Code:
BODY { 
	background:url(/html//civis/threads/css-height-problems.1126786/post-20966534/images/backgroundlines.gif) repeat;
	position:relative;
	height:100%;
	text-align:left;
	margin:0px;
	padding:0;
}

html {
   height:100%;
}

#wrapper {
	position:relative;
	height:100%;
	width:1098px;
	margin-left:0px;
} 



#container {
	background-color:#fff;
	background-image:url(/html//civis/threads/css-height-problems.1126786/post-20966534/images/fadelines.gif);
	background-repeat:repeat-y;
	position:relative;
	top:0px;
	height:100%;
	width:1098px;
}


#work {
	position:relative;
	margin-top:0px;
	margin-left:225px;
	text-align:left;
	height:100%;
}
#sideBar {
	position: relative;
	min-height: 100%;
	height: 100%;
	width: 217px;
	background-color:#FFF;
	top: 0px;
	left: 0px;
	float: left;
}

.shadow-right {
	background: url(/html//civis/threads/css-height-problems.1126786/post-20966534/images/rightSide.png) repeat-y;
	position: relatvie;
	height: 100%;
	left: 210px;
	top: 0px;
	width: 7px;
	margin-top: 0px;	
	float: right;
}


.sideBar-lines {
	background-image: url(/html//civis/threads/css-height-problems.1126786/post-20966534/images/backgroundlines.gif);
	background-repeat: repeat;
 	position: relative;
	float: left;
	left: 0px;
	top: 0px;
	width: 210px;
	margin-top: 0px;
	min-height: 100%;
}

I left out most of the classes and font styling, the above is everything that should be going from top to bottom. And here is how the HTML is structured:
Code:
<body>
<div id="wrapper">
	<div id="container">
		<div id="sideBar">
    		<div class="shadow-right">&nbsp;</div>
    		<div class="sideBar-lines">
   				Content
    		</div>
    	</div>
		<div id="work">
			Content
		</div>  
	</div>
</div>
</body>
 

technophile

Ars Legatus Legionis
23,768
Stray Toaster":3f78n0yw said:
I have the body, html and everything else set to height: 100%
I haven't tested, but I suspect this is your problem; 100% means 100% of the container's height, which in this case is the viewport of the browser.

Remove the height: 100% and leave it at auto (on at least body and html; you probably don't actually need it on much except possible the sidebar div) and see if that helps.

If that doesn't do it, you may need to add an overflow: hidden to the container div(s), that will paradoxically force them to expand to their contents' size (for example in the case of floated child divs) as long as you have an explicit width on them.
 

Stray Toaster

Ars Tribunus Militum
2,292
Subscriptor++
That fixed half of the problem.

The new problem involves trying to make the content div stretch all the way to the bottom of the browser when there is no actual content to push down.

Right now I am getting half a page of my background lines below the content.

My current work around is to set an inline min-height style on the page in question for the container div, but I feel like there must be a better way.
 

Stray Toaster

Ars Tribunus Militum
2,292
Subscriptor++
Ah typos...

I actually ditched that div all together, and changed the whole page to have one repeating background image, a 1000px wide 6px tall


I sort of solved my problem. I tried min-height on the wrapper (and container for what it's worth) but it was giving me some errors if the browser window was sized too small. So, I did the following:

Body: 100% height
Wrapper: 100% height
Container: No height specified, set overflow to hidden.
Sidebar: 100% height.

I then set both wrapper and container to have the same background image.

In cases where the content is longer than the browser window, the Container div gets stretched to the bottom, so my background images work.

When the content is shorter than the browser window, the wrapper div is being stretched to the body, being the full browser window and so everything makes it to the bottom.

The code maybe isn't ideal, but it looks how I want it, which is the important part. And it check outs in Chrome, Firefox and IE8 (in IE8 Mode, IE7 mode and Quirks mode) so time to finish this damn thing.

Good times.
 
Status
Not open for further replies.