It's been over a year now since I did any CSS so I'm very rusty, bear with me! I'm sure this is a very simple question, but what I want to do is have a static container fixed in the centre of the page, then two columns using floats. In firefox the floating column always appears below the container, what am I doing wrong?
The float will always appear below the container if #container comes first in the html - floats have to come before the items they are to be positioned beside.
The issue is a fairly common one. You need to put a mini "clear float" div at the bottom of your container div to set the "bottom" edge of the container box.
Here's the css for you.
body {
/*whatever background information you want here, but having white on white is boring. */
}
#container {
width:800px;
margin-left:auto;
margin-right:auto;
/* I'd add a top margin, just for aesthetics, this can be a 1-2 em height */
background-color:#FFFFFF;
height:auto;
}
#left-bar {
width:260px;
float:left;
background-color:#ccc;
/* I added the grey color so I could see the difference */
border:1px solid #000;
/* use hex color codes if you can */
min-height:100px;
}
#clearall {
clear:both
}
</style>
Then you order the divs like this
Container
left-bar
clearall
Container
This will fix your problem in Firefox, IE doesn't like minimum heights, you you may want to look at putting a spacer image inside the box that will create the same effect.
You need to change the left-bar style to read as follows:
#left-bar {
width:260px;
float:left;
background-color:#ccc;
border:1px solid #000;
min-height:100px;
height:auto;
height:100px;
}
The float will always appear below the container if #container comes first in the html - floats have to come before the items they are to be positioned beside.
Bookmarks