...

View Full Version : divs not lining up; div height double what it should be



GarrettVD
12-21-2007, 03:27 AM
Hi,

I'm having a bit of trouble making a three-columned div layout. The middle column ("content") and the right column are rendering correctly in both FF and IE.

However, in IE, you'll notice that there is a slight 2px or so "space" between the left div and the "content" div. Can you tell my why this is, and how it can be corrected?

Also, The columns themselves are expended to the full height of the browser, however there is a space underneath them that continues for another 100% height or so. I also don't know why this is.

The website can be seen here: http://www.epalsconnect.com/clinic/index.html
CSS file here: http://www.epalsconnect.com/clinic/styles/style.css

Any help would be greatly appreciated. Thanks,

Garrett

HTML:


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>#PAGENAME#</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link rel="stylesheet" type="text/css" href="./styles/style.css" />
</head>

<body>
<div id="wrapper">
<div id="left"></div>
<div id="content">CONTENT</div>
<div id="right"></div>
</div>
</body>
</html>


CSS:


body, html {
width: 100%;
height: 100%;
margin: 0px;
}

body {
font-family: Arial, Helvetica, sans-serif;
background-color: #3e97f3;
}

#wrapper {
text-align: left;
margin: 0px auto;
width: 100%;
height: 100%;
background: url("/path/to/your/background_cols.gif") repeat;
}

#left {
float: left;
width: 200px;
height: 100%;
background: url('../images/leftBg.jpg') right repeat-y;
}

#right {
position: relative;
top: 0;
right: 0;
width: 200px;
height: 100%;
background: url('../images/rightBg.jpg') left repeat-y;
}

#content {
border-left: 1px solid #000000;
border-right: 1px solid #000000;
margin-right: 200px;
margin-left: 200px;
height: 100%;
background: #ffffff url('../images/contentBg.gif') bottom right no-repeat;
}

Majoracle
12-21-2007, 04:29 AM
Well, the reason it's expanding another 100&#37; is because you right column is being forced under the left column. The reason for this is your borders on the content div. Borders, paddings, and margins aren't counted towards to width of a div. So basically what you're getting is a total of 100% PLUS 2 pixels width. The result is the third column being forced down to the next row. Taking out the border will fix it. Mixing percents and pixels to form the width is always going to lead to problems like this. Also, just fair warning, when you have a height in percent, and the content expands beyond the height of the browser, the div will not span, and the content will just overflow it.

Excavator
12-21-2007, 04:41 AM
Hello GarrettVD,
Get your columns in order with this (I hope... didn't look at it in IE)
CSS
body, html {
width: 100%;
height: 100%;
font-family: Arial, Helvetica, sans-serif;
text-align: left;
background: #3e97f3 url("http://www.epalsconnect.com/clinic/images/background_cols.gif");

}
* {
margin: 0;
padding: 0;
border: none;
}


#left {
float: left;
width: 200px;
height: 300px;
background: url('http://www.epalsconnect.com/clinic/images/leftBg.jpg')right repeat-y;
}

#right {
width: 200px;
height: 300px;
float: right;
background: url('http://www.epalsconnect.com/clinic/images/rightBg.jpg') left repeat-y;
}

#content {
height: 300px;
margin: 0 200px;
border-left: 1px solid #000000;
border-right: 1px solid #000000;
background: #ffffff url('http://www.epalsconnect.com/clinic/images/contentBg.gif') bottom right no-repeat;
}

and re-order your markup like this:


<div id="left"></div>
<div id="right"></div>
<div id="content">CONTENT</div>

You may need to play with the margins on #content if the borders make a float drop.

For a full height solution that doesn't break when you put text in it, have alook at my example. (http://nopeople.com/CSS/full-height-layout/)

GarrettVD
12-21-2007, 08:48 AM
Thanks, guys! I appreciate the help!

@ Majoracle: I understand what you mean about taking into account the margins, borders, and paddings. But it renders beautifully in FF -- The left and right cols are nice and snug up against the content col. But in IE it's showing an extra 2 or so pixels on each side... Can you tell me why this is, given my CSS / HTML code below? Thanks a lot!



@ Excavator: Awesome, thanks for the link! I checked it out and I tweaked my HTML / CSS slightly, so that the text in the content column doesn't "spill out" when the 100&#37; height of the browser screen has been surpassed.

However, if you take a look at my website, the left and right columns are not extending to the same length as that of the Content column. Setting the height: 100% will only ensure that the first 100% is filled with background image, but what about the rest? Is there a way to fix this?

Thanks again, guys!

http://www.epalsconnect.com/clinic/index.html <- Website
http://www.epalsconnect.com/clinic/styles/style.css <- Style

HTML:


<body>
<div id="wrap">
<div id="left">aaa</div>
<div id="right">bbb</div>
<div id="content"><p>CONTENT CONTENT CONTENT CONTENT CONTENT [etc...]</p></div>
</div>
</body>


CSS:


body {
height: 100%;
font-family: Arial, Helvetica, sans-serif;
text-align: left;
background: #3e97f3 url("http://www.epalsconnect.com/clinic/images/background_cols.gif");
}

html {
height: 100%;
}

* {
margin: 0;
padding: 0;
border: none;
}

#wrap {
width: 1000px;
margin: 0 auto;
text-align: left;
min-height: 100%;
}


* html #wrap {
height: 100%
}

#left {
float: left;
width: 100px;
background: #3e97f3 url('http://www.epalsconnect.com/clinic/images/leftBg.jpg') right repeat-y;
margin: 0;
}

#right {
width: 100px;
float: right;
background: #3e97f3 url('http://www.epalsconnect.com/clinic/images/rightBg.jpg') left repeat-y;
}

#content {
height: 100%;
margin-left: 100px;
margin-right: 100px;
background: #ffffff url('http://www.epalsconnect.com/clinic/images/contentBg.gif') bottom right no-repeat;
}

effpeetee
12-21-2007, 09:51 AM
All the columns look the same height to me. Both IE7 and FFox 2.

Frank

Majoracle
12-21-2007, 10:38 AM
@ Frank: They're not. He has a gradient on each of the right and left columns. It's hard to notice if you're not looking right at it, but it's there. You can only see it behind the text.

-----

Now, the short version is getting a div to span the same height as that of another is impossible. When people have 2 column layouts and they want to accomplish this, they have a wrap around the left and right columns with a vertically repeating background image. This way, the wrap spans the height of the longest column (no matter which) and so does it's background image. The illusion is 2 columns that appear to span the same height.

Doing it with 3 columns is a bit more difficult. Did come up with a solution for you though. Here:

replace CSS with:

body {
font-family: Arial, Helvetica, sans-serif;
text-align: left;
background: #3e97f3 url('http://www.epalsconnect.com/clinic/images/leftBg.jpg') top left repeat-y;
}

html {
height: 100&#37;;
}

* {
margin: 0;
padding: 0;
border: none;
}

#wrap {
width: 1000px;
height: 100%;
margin: 0 auto;
text-align: left;
min-height: 100%;
background: transparent url('http://www.epalsconnect.com/clinic/images/rightBg.jpg') top right repeat-y;
}

* {
margin: 0;
padding: 0;
}

* html #wrap {
height: 100%
}

p {
margin: 0;
padding: 0px;
}

#left {
float: left;
width: 100px;
margin: 0;
}

#right {
width: 100px;
float: right;
}

#content {
height: 100%;
margin-left: 100px;
margin-right: 100px;
background: #ffffff url('http://www.epalsconnect.com/clinic/images/contentBg.gif') bottom right no-repeat;
}

Wont have to change your HTML.

Should work. Good luck.

Excavator
12-21-2007, 06:04 PM
However, if you take a look at my website, the left and right columns are not extending to the same length as that of the Content column. Setting the height: 100% will only ensure that the first 100% is filled with background image, but what about the rest? Is there a way to fix this?


Good morning GarettVD, Have a look at this:http://nopeople.com/CSS/full-height-3column/

GarrettVD
12-21-2007, 09:01 PM
Thanks again, guys! Very helpful information. I've gone with the easiest, and possibly best choice of setting just one body background image, which will repeat-y, centered, for the length of the page. Doing it the other way is too much hassle for what it's worth.

Thanks! :D



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum