Log in

View Full Version : Centered 2 column layout with fixed width AND percentage width



yanwhite
10-30-2008, 03:59 PM
I need to create a centered 2 column layout using a combination of fixed width AND percentage width (and also using min and max width for the body or container).

The body/container min/max width will be 770 to 970 pixels wide.
The right column is 360 pixels wide.
The left column should be stretching to fit the remaining width.

I searched around and found a couple of solutions, but none that approached satisfying all of the above needs.

Can anyone help?

TheJoshMan
11-01-2008, 05:15 PM
This is a code found here: http://www.dynamicdrive.com/style/layouts/item/css-fixed-layout-22-fixed-fixed/ that I have modified to suite your needs.



<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Dynamic Drive: CSS Fixed Layout #2.2- (Fixed-Fixed)</title>
<style type="text/css">

body{
margin:0;
padding:0;
line-height: 1.5em;
}

b{font-size: 110%;}
em{color: red;}

#maincontainer{
min-width: 770px; /*Min-Width of main container*/
max-width: 970px; /*Max-Width of main container*/
margin: 0 auto; /*Center container on page*/
}

#topsection{
background: #EAEAEA;
height: 90px; /*Height of top section*/
}

#topsection h1{
margin: 0;
padding-top: 15px;
}

#contentwrapper{
float: left;
width: 100%;
}

#contentcolumn{
margin-right: 360px; /*Set right margin to RightColumnWidth*/
}

#rightcolumn{
float: left;
width: 360px; /*Width of right column*/
margin-left: -360px; /*Set left margin to -(RightColumnWidth) */
background: #FDE95E;
}

#footer{
clear: left;
width: 100%;
background: black;
color: #FFF;
text-align: center;
padding: 4px 0;
}

#footer a{
color: #FFFF80;
}

.innertube{
margin: 10px; /*Margins for inner DIV inside each column (to provide padding)*/
margin-top: 0;
}

</style>

<script type="text/javascript">
/*** Temporary text filler function. Remove when deploying template. ***/
var gibberish=["This is just some filler text", "Welcome to Dynamic Drive CSS Library", "Demo content nothing to read here"]
function filltext(words){
for (var i=0; i<words; i++)
document.write(gibberish[Math.floor(Math.random()*3)]+" ")
}
</script>
<!--=========BEGIN DO NOT REMOVE | THIS MAKES IE 6 RECOGNIZE MIN/MAX WIDTH=============-->
<!--[if lt IE 7]>
<script src="http://ie7-js.googlecode.com/svn/version/2.0(beta3)/IE7.js" type="text/javascript"></script>
<![endif]-->
<!--=========END DO NOT REMOVE | THIS MAKES IE 6 RECOGNIZE MIN/MAX WIDTH=============-->

</head>
<body>
<div id="maincontainer">

<div id="topsection"><div class="innertube"><h1>CSS Fixed Layout #2.2- (Fixed-Fixed)</h1></div></div>

<div id="contentwrapper">
<div id="contentcolumn">
<div class="innertube"><b>Content Column: <em>Fixed</em> (expands width to compensate for right column)</b> <script type="text/javascript">filltext(45)</script></div>
</div>
</div>

<div id="rightcolumn">
<div class="innertube"><b>Right Column: <em>360px</em></b> <script type="text/javascript">filltext(30)</script></div>

</div>

<div id="footer"><a href="http://www.dynamicdrive.com/style/">Dynamic Drive CSS Library</a></div>

</div>
</body>
</html>