Center CSS colums shifts when more content is added

follicle

New Member
Greetings,

I've run into this issue in the past, but I never really felt like getting it addressed until now. I'm pretty frustrated.

I'm working on a personal portfolio website and I am using one of Dreamweaver's simple CSS templates – a header, main content cell, and footer, all of which is centered on the page. I am almost done with the website design; however, I had to limit the amount of content I put on each page because of an odd issue I am having. As soon as I add enough content on a page to allow for a scroll bar to appear, the center column (containing the header, main content cell, and footer div tags) shifts ever-so-slightly to the left. It's fairly noticeable while going from a page that has very little content to a page with a lot of content. You can actually see the entire column shift slightly to the left and then back again as you click to another page with less content.

At first, I thought it might be an issue with my page design, but then I discovered that it actually occurs in the template as well. Below is the code for the template I am using. I have edited the code below so that all of the content appears on one page without a scroll bar. If you attempt to add a paragraph or two, a scroll bar will appear, and the entire center column will shift slightly to the left. See the code below in red:

<!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>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
<style type="text/css">
<!--
body {
font: 100% Verdana, Arial, Helvetica, sans-serif;
background: #666666;
margin: 0; /* it's good practice to zero the margin and padding of the body element to account for differing browser defaults */
padding: 0;
text-align: center; /* this centers the container in IE 5* browsers. The text is then set to the left aligned default in the #container selector */
color: #000000;
}

/* Tips for Elastic layouts
1. Since the elastic layouts overall sizing is based on the user's default fonts size, they are more unpredictable. Used correctly, they are also more accessible for those that need larger fonts size since the line length remains proportionate.
2. Sizing of divs in this layout are based on the 100% font size in the body element. If you decrease the text size overall by using a font-size: 80% on the body element or the #container, remember that the entire layout will downsize proportionately. You may want to increase the widths of the various divs to compensate for this.
3. If font sizing is changed in differing amounts on each div instead of on the overall design (ie: #sidebar1 is given a 70% font size and #mainContent is given an 85% font size), this will proportionately change each of the divs overall size. You may want to adjust based on your final font sizing.
*/
.oneColElsCtrHdr #container {
width: 46em; /* this width will create a container that will fit in an 800px browser window if text is left at browser default font sizes */
background: #FFFFFF;
margin: 0 auto; /* the auto margins (in conjunction with a width) center the page */
border: 1px solid #000000;
text-align: left; /* this overrides the text-align: center on the body element. */
}
.oneColElsCtrHdr #header {
background: #DDDDDD;
padding: 0 10px 0 20px; /* this padding matches the left alignment of the elements in the divs that appear beneath it. If an image is used in the #header instead of text, you may want to remove the padding. */
}
.oneColElsCtrHdr #header h1 {
margin: 0; /* zeroing the margin of the last element in the #header div will avoid margin collapse - an unexplainable space between divs. If the div has a border around it, this is not necessary as that also avoids the margin collapse */
padding: 10px 0; /* using padding instead of margin will allow you to keep the element away from the edges of the div */
}
.oneColElsCtrHdr #mainContent {
padding: 0 20px; /* remember that padding is the space inside the div box and margin is the space outside the div box */
background: #FFFFFF;
}
.oneColElsCtrHdr #footer {
padding: 0 10px; /* this padding matches the left alignment of the elements in the divs that appear above it. */
background:#DDDDDD;
}
.oneColElsCtrHdr #footer p {
margin: 0; /* zeroing the margins of the first element in the footer will avoid the possibility of margin collapse - a space between divs */
padding: 10px 0; /* padding on this element will create space, just as the the margin would have, without the margin collapse issue */
}
-->
</style></head>

<body class="oneColElsCtrHdr">

<div id="container">
<div id="header">
<h1>Header</h1>
<!-- end #header --></div>
<div id="mainContent">
<h1> Main Content </h1>
<p>Exter text here. Exter text here. Exter text here. Exter text here. Exter text here. Exter text here. Exter text here. Exter text here. Exter text here. Exter text here. Exter text here. Exter text here. Exter text here. Exter text here. Exter text here. Exter text here. Exter text here. Exter text here. Exter text here. Exter text here. Exter text here. Exter text here. Exter text here. Exter text here. Exter text here. Exter text here. Exter text here. Exter text here. Exter text here. Exter text here. Exter text here. Exter text here. Exter text here. Exter text here. Exter text here. Exter text here. Exter text here. Exter text here. Exter text here. Exter text here. Exter text here. Exter text here. Exter text here. Exter text here. Exter text here. Exter text here. Exter text here. Exter text here. Exter text here. Exter text here. Exter text here. Exter text here. Exter text here. Exter text here. Exter text here. </p>
<!-- end #mainContent --></div>
<div id="footer">
<p>Footer</p>
<!-- end #footer --></div>
<!-- end #container --></div>
</body>
</html>


Any idea of what's going on or how to correct this issue? Thanks in advance for any replies!
 

smoovo

New Member
Solution

Hi, there.

Use the code I'm giving you to every page and every website you are going to build from now on. I'm giving you a powerful solution... simple, but powerful!

Add to your CSS at the beginning

HTML:
html {height:101%;}

That's it, Enjoy.

____________________
SMooVo- Web Design
[email protected]
www.SMooVo.com
 

PixelPusher

Super Moderator
Staff member
Sounds like you are talking about a scrollbar in the browser window. This is default behavior and there isn't a way to change this.
 

smoovo

New Member
Tables not default anymore because there is a better alternative (sometimes). If you have some better solution for follicle, please share it with us, i will be glad to discover new ideas.

By the way, correct is a thing that still legal, and it accomplish your goal. Tables still a validate code even in 2010 with HTML5 and CSS3.
So I'm trying to figure very hard, what correct are you talking about :confused:

____________________
[email protected]
www.SMooVo.com – Web Design
 
Last edited:

PixelPusher

Super Moderator
Staff member
Tables not default anymore because there is a better alternative (sometimes). If you have some better solution for follicle, please share it with us, i will be glad to discover new ideas.

By the way, correct is a thing that still legal, and it accomplish your goal. Tables still a validate code even in 2010 with HTML5 and CSS3.
So I'm trying to figure very hard, what correct are you talking about :confused:

____________________
[email protected]
www.SMooVo.com – Web Design

Semantically correct.
 
Top