0

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;
}

Fiddle

aksu
  • 5,221
  • 5
  • 24
  • 39
SorenRomer
  • 217
  • 1
  • 10

2 Answers2

3

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.

Community
  • 1
  • 1
chaenu
  • 1,915
  • 16
  • 32
0

In the jsfiddle, it seems that they do have the same height and background. Am I missing something ?

Baruch Oxman
  • 1,616
  • 14
  • 24
  • The problem is that I want the semi-transparent background. Now, I could add that to the content and sidebar, but the height will differ as soon as more lines of text are added to one or the other... – SorenRomer Jan 25 '14 at 14:19