Forum Moderators: not2easy

Message Too Old, No Replies

Please help!

Novice question about floating elements

         

elagasse

11:46 pm on Sep 28, 2006 (gmt 0)

10+ Year Member



I have only recently started learning HTML and CSS. I've been able to work my way through it for the most part but I am stuck on this one issue and need help before I go completely insane trying to make it work!

I have three divs (headbanner, leftcontent and centercontent). I want the headbanner up top and the leftcontent and centercontent to line up across the page below it. The site displays exactly how I want it to in high screen resolutions and when the browser window is fully expanded. But when the browser window is not fully expanded, the "centercontent" is too big to display and gets pushed down below "leftcontent." I would much prefer a horizontal scroll bar to appear and "centercontent" to display alongside "leftcontent" as usual. I've had it working in Firefox and Internet Explorer before but do not know what I did and now it doesn't work anymore!

Please take a look at my site, [thefeaturedtable.com...] and help me with this. Thank you so much.

penders

12:20 am on Sep 29, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Hi elagasse, welcome to WebmasterWorld... Your #leftcontent DIV is your navigation and appears in a fixed width column down the left. Your #centercontent DIV is your main content and takes up most of your page, so it looks odd when it suddenly jumps down to below your navigation when there isn't room. You are floating both of these elements to the left.

One way to get your desired result is to not float your elements at all, but position your #leftcontent DIV absolutely (which takes it out of the flow of the page) on the left side of the screen of width say 200px. And let your #centercontent DIV flow normally, but give it a large left margin (say 210px) to allow room for your #leftcontent DIV (otherwise your center DIV will appear underneath your left DIV!). This will avoid the center DIV jumping down to below your left DIV, since they are no longer floated.

eg.

#leftcontent { 
position: absolute;
top: 50px;
left: 10px;
width: 200px;
height: 500px;
}

#centercontent {
margin-left: 210px; /* Allow for #leftcontent */
}

... you may be able to keep some of your current rules, but remove the

float:left;
rules. The values given here are just to show the idea. This is effectively a fluid two-column layout, the left column is fixed, but the center would stretch to fill the available space (if you let it).

Hope that helps.

elagasse

12:59 am on Sep 29, 2006 (gmt 0)

10+ Year Member



It worked! I really appreciate your help, that was driving me crazy. Thanks again!

panchosansa

1:01 am on Sep 29, 2006 (gmt 0)

10+ Year Member



Welcome, elagasse. I am a beginner myself but I tried doing something like the thing that you want and I think it worked out. In my code the float:left is still there but you have to use percentage not pixel in setting the dimensions of your divs which may cause your layout to look differently centralized in different browsers as well as in different screen resolution (the last, of course, is true for pixels also).
Here is my code:


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>New Document</title>
<style type="text/css">
*
{
margin:0;
padding:0;
}
body
{
background:gray;
}
.left
{
width:15%;
float:left;
}
h2
{
background:black;
color:Green;
}
.content
{
background:blue;
border:solid 5px black;
height:200px;
float:left;
width:70%;/*set it to suit you*/
margin-top:10px;/*margin-top*/
}
ul
{
margin-left:25px;/*to make the bullets visible*/
margin-top:10px;/* margin-top to allign with content section*/
}
</style>
</head>
<body>
<h2>here goes the header</h2>
<div class="left">
<ul>
<li>Item one</li>
<li>Item two</li>
<li>Item three</li>
</ul>
</div>
<div class="content">text text text text text text text text text text text text text text
text text text text text text text text text text text text text text
text text text text text text text text text text text text text text
text text text text text text text text text text text text text text
text text text text text text text text text text text text text text
text text text text text text text text text text text text text text
text text text text text text text text text text text text text text
text text text text text text text text text text text text text text
text text text text text text text text text text text text text text
text text text text text text text text text text text text text text
</div>
</body>
</html>