Reputation: 217
I'm trying to get the main content area and the sidebar to have the same background and the same height. I thought it would work if I the both sub-classes in the same <div>
, but obviously it doesn't work. Is there a simple way to achieve this, or do I have to go for some of the faux column trickery?
HTML:
<body>
<div id="wrapper">
<div id="header">
<h1>Page title</h1>
<h3>Subtitle</h3>
</div>
<div id="main">
<div class="content">This is the main area</div>
<div class="sidebar">This is the sidebar</div>
</div>
<div id="footer">
The footer;
</div>
</div>
</body>
</html>
CSS:
body {
margin: 0;
padding: 0;
background-color: #ff1;
}
#wrapper {
width: 800px;
margin: 0 auto;
}
#header {
background-color: rgba(255,255,255,0.7);
}
#nav {
background-color: rgba(255,255,255,0.7);
}
#main {
background-color: rgba(255,255,255,0.7);
}
.content, .sidebar {
float: left;
padding: 20px;
}
.content {
width: 510px;
}
.sidebar {
width: 210px;
}
#footer {
background-color: rgba(255,255,255,0.7);
clear:both;
}
Upvotes: 0
Views: 120
Reputation: 2025
The wrapping container ( #main ) doesn't expand to the height of the child elements, because they both are floated. You could add a clearfix or just
overflow: auto;
to the #main element.
Upvotes: 3
Reputation: 1636
In the jsfiddle, it seems that they do have the same height and background. Am I missing something ?
Upvotes: 0