Log in

View Full Version : Background colour for main div



sivlock
03-13-2009, 12:14 PM
What im trying to do is keep the main content and every div within the main div white without having to set the background colour white to each floating div, any help people? Cheers. Code below


<body>
<div id="container">
<div id="left_header">IMAGE HERE</div>
<div id="right_header">IMAGE HERE</div>
</div>
</body>

body {
margin: 0;
padding: 0;
text-align: center;
background-image: url(images/background.jpg);
}
#container {
width: 875px;
text-align: left;
background-color: #FFFFFF;
margin-top: 0;
margin-right: auto;
margin-bottom: 0;
margin-left: auto;
} #left_header {
width: 207px;
float: left;
}
#right_header {
width: 668px;
float: right;
}

Snookerman
03-13-2009, 01:18 PM
Add this to your CSS code:

#container {
width: 875px;
text-align: left;
background-color: #FFFFFF;
margin-top: 0;
margin-right: auto;
margin-bottom: 0;
margin-left: auto;
overflow: hidden;
}

Good luck!

sivlock
03-13-2009, 02:33 PM
Thanks that works quite nicely although I have actually opted to use a small 1pixel image to fill the space below so the container recognizes there's something in it.

Snookerman
03-13-2009, 04:04 PM
Do you mean a spacer gif? That is really not recommended.

sivlock
03-13-2009, 04:07 PM
yeah whys that then?

Schmoopy
03-13-2009, 04:08 PM
Yes, spacer gifs were something people used to have to put in if they used tables for layout, with CSS you really shouldn't need to have them.

sivlock
03-13-2009, 04:27 PM
Yeah i see what you mean and works better with the css. Im just starting out using divs and css before I used to use some tables too but i never used spacer gifs.