0

I have a site with two columns, a content one and a menu one. The menu is fairly large and will sometimes be taller than the content pane. I basically have the following setup at the moment:

.container {
    width: 300px;
    margin: auto;
    background: red;
}
#first {
    width: 75%;
    float: left;
    background-color: blue;
}
#second {
    width: 25%;
    float: left;
    background-color: green;
    color: white;
}
#clear {
    clear: both;
}
a {
    color: white;
}
* {
    color: white;
}
<div class='container'>
    <div id="first">Some content</div>
    <div id="second">Menu<br>Menu<br>Menu<br>Menu<br>Menu<br>Menu</div>
    <div id="clear"></div>
</div>

The #first div doesn't reach the bottom of the container, even when I add height: 100%;. How can I fix this?

J Atkin
  • 3,080
  • 2
  • 19
  • 33

3 Answers3

1

You need a height on its parents all the way to the html/body tags

.container {
  display: flex;
  width: 300px;
  margin: auto;
  background: red;
}
#first {
  flex: 1;
  width: 75%;
  background-color: blue;
}
#second {
  flex: 1;
  width: 25%;
  height: 300px;
  background-color: green;
  color: white;
}
a {
  color: white;
}
* {
  color: white;
}
    <div class='container'>
        <div id="first">Some content</div>
        <div id="second">Menu</div>
    </div>

For older browsers...display: table

.container {
  display: table;
  width: 300px;
  margin: auto;
  background: red;
}
#first {
  display: table-cell;
  width: 75%;
  background-color: blue;
}
#second {
  display: table-cell;
  width: 25%;
  height: 300px;
  background-color: green;
  color: white;
}
a {
  color: white;
}
* {
  color: white;
}
<div class='container'>
        <div id="first">Some content</div>
        <div id="second">Menu</div>
    </div>
Asons
  • 84,923
  • 12
  • 110
  • 165
1

You can use flexbox

.container {
width: 300px;
margin: auto;
background: red;
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
}
#first {
width: 75%;
float: left;
background-color: blue;
}
#second {
width: 25%;
float: left;
background-color: green;
color: white;
}
#clear {
clear: both;
}
a {
color: white;
}
* {
color: white;
}
<div class='container'>
<div id="first">Some content</div>
<div id="second">Menu<br>Menu<br>Menu<br>Menu<br>Menu<br>Menu</div>
<div id="clear"></div>
</div>
Felix A J
  • 6,300
  • 2
  • 27
  • 46
0

you have to give the container an height because if not #first will be 100% of how what if the parent don't have a height the child can not be 100% of it!!

Maybe you give him 300px like the #second or less and then you give #first 100% and it will work

CodeWeis
  • 846
  • 6
  • 19