How to make a CSS three column layout with static middle column?

I'd like to have a three column layout in CSS such that the center column is a set width, say 900px, while the left column and the right column expand to fill up the area that the middle column does not.  I'd like to use only DIVs.  I would also like to make the heights of the flanking columns match that the height of the middle column (which is where the content will reside).  

Is this possible to do with CSS only?  
LVL 4
ariestavAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

lpxtechCommented:
This is possible, you have to set your width property in css to a set value for the center color for example width: 500px; and a percentage for the other two columns ex. width: 20%;

I have attached some example code.
<style type="text/css">
div {
	float: left;
	border:solid #000 1px;
}
 
#col-1, #col-3 {
	width: 20%;
}
 
#col-2 {
	width: 500px;
}
</style>
</head>
<body>
<div id="col-1">
This is col 1
</div>
<div id="col-2">
This is col 2
</div>
<div id="col-3">
This is col 3
</div>
</body>
</html>

Open in new window

0
ariestavAuthor Commented:
Thank you for the code, but how can I ensure that the middle column is always aligned in the center?

Also, I wanted the flanking columns to get as thin as 1px. when the browser gets thinner.

Is that possible?
0
ariestavAuthor Commented:
Attached is a diagram showing how I'd like the fluid cols to work against the static, center column.  Is this possible with CSS DIVs?

Thanks!

browserWidths.jpg
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

lpxtechCommented:
By using float: left on all tree columns, they will be aligned in the order that they are in the html. Also you may want to add <div class="clear">&nbsp;</div> style to the element directly following the third column. This will prevent the columns from displaying over any content below the columns.
CSS:
 
.clear {
  clear: both;
}

Open in new window

0
lpxtechCommented:
Also, if you would like it all to fill the browser you can have width: 60% on the center col and 20% on each side. If you do it that way you can set a minimum width on the center column by using the code below.
#col-2 {
  width: 60%;
  min-width: 500px; //Firefox minimum width
  _width: 500%; // IE minimum width
}

Open in new window

0
uzzidesignCommented:
The following galleries provide many different 3 column CSS layouts with their source.
http://blog.html.it/layoutgala/
http://mitchbryson.com/free-css-templates
0
ariestavAuthor Commented:
@uzzidesign:  I checked out the url you sent, and I didn't see any examples that showed the design spec I uploaded earlier.

@Ipxtech:  I tried your solution, but it didn't work in a couple of browsers I was targeting.

I decided to go with a simple three column table layout and place the div elements within those columns.  I know it's a hack, but in order to get it to work the way I wanted across all browsers, I had to do it like this.

Thanks again for your time and help!
0
yessirnosirCommented:
I didn't see your post earlier, but have attached some code that I think does what you want.  
<!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>3 Column | Left/Right Fluid - Center Fixed</title>
 
<style type="text/css">
html, body {
margin: 0;
padding: 0;
height:100%;
}
 
#centercol {
width: 600px;
height: 100%;
margin: 0 auto;
background: white;
 
}
#lefthalf {
position: absolute;
left: 0;
top: 0;
width: 50%;
height:100%;
}
#righthalf {
position: absolute;
right: 0;
top: 0;
width: 50%;
height:100%;
}
#leftcol {
margin-right: 300px;
background: blue;
height: 100%;
 
}
#rightcol {
margin-left: 300px;
background: red;
height: 100%;
}
 
</style>
 
</head>
<body>
<div id="lefthalf">
    <div id="leftcol">left column</div>
</div>
 
<div id="centercol">center column</div>
 
<div id="righthalf">
    <div id="rightcol">right column</div>
</div>
 
</body>
</html>

Open in new window

0
yessirnosirCommented:
came across another 3 column/fixed middle layout, even better than the one I posted above:
http://www.gunlaug.no/tos/moa_27a.html
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
yessirnosirCommented:
late to the party, but I have just posted two different layouts that I think answer the question...
0
ariestavAuthor Commented:
I used "partially accurate" because I have not tested it in many browsers on both Mac and PC
0
yessirnosirCommented:
thanks... fyi have been working this layout for another EE question, and as a result of some feedback on that other post, I've been fine tuning the first code I posted above.  Latest version has been modified to handle narrow browser windows better, including a fix to stop the layout from breaking in IE6 when browser window is squeezed too much... this relies on a CSS expression to simulate the "min width" property.  Expressions aren't the preferred way of doing anything (!) but the expression only kicks in for IE users, so it's not a bad compromise to deal with that browser's shortcomings.  Anyway, am posting latest updated code, for what it's worth...
<!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>3 Column Left/Right Fluid - Center Fixed With min width expression to fix IE6 compatibility</title>
 
<style type="text/css">
html, body {
margin: 0;
padding: 0;
height:100%;
}
#container {
position:relative;
width:100%;
min-width:1050px;
height:100%;
} 
#centercol {
position:relative;
width: 950px;
height: 100%;
margin: 0 auto;
background: white;
}
 
#lefthalf {
position: absolute;
left: 0;
top: 0;
width: 50%;
height:100%;
}
 
#righthalf {
position: absolute;
right: 0;
top: 0;
width: 50%;
height:100%;
}
 
#leftcol {
margin-right: 475px;
background: blue;
height: 100%;
}
 
#rightcol {
margin-left: 475px;
background: red;
height: 100%;
}
/* following code for IE min width based on example at www.gunlaug.no/contents/wd_additions_14.html  */
* html div#container {width: 1050px /* fallback value */;
width:expression(((document.compatMode && 
document.compatMode=='CSS1Compat') ? 
document.documentElement.clientWidth : 
document.body.clientWidth) < 1051 ? "1050px" : "100%"); }
 
</style>
 
</head>
<body>
<div id="container">
 
<div id="lefthalf">
    <div id="leftcol">left column</div>
</div>
 
<div id="centercol">center column
 
</div>
 
<div id="righthalf">
    <div id="rightcol">right column</div>
</div>
</div> 
</body>
</html>

Open in new window

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Languages and Standards

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.