44

I can't figure this one out. I've got a simple set of divs with a header, sidebar and content area. The header is full width, the side and content are floated left.

I need the sidebar (for the background) to fill 100% of the page height, but when I inspect element in chrome, the <body> is actually ending long before the bottom of the page, which seems to be limiting the height of my sidebar.

What is keeping the <body> from filling the full page here?

    ​<body>
    <div id="head">
    </div>
<div id="sidebar">
    <div>
        <div id="menu">
            <ul>
                <li><a href="/dashboard.php"><img src="/img/blank.png" alt="home" id="home_ico">Home</a>
                </li>
                <li class="admin"><a><img src="/img/blank.png" alt="home" id="users_ico">Users</a>
                    <ul class="submenu" style="display: none;">
                        <li><a href="/users">Manage users</a></li>
                        <li><a href="/users/add.php">Add a user</a></li>
                    </ul>
                </li>

                <li class=""><a><img src="/img/blank.png" alt="home" id="clients_ico">Clients</a>
                    <ul class="submenu" style="display: none;">
                        <li><a href="/client_orgs">Manage clients</a></li>
                        <li><a href="/client_orgs/add.php" class="admin">Add a client</a></li>
                    </ul>
                </li>


                <li class=""><a><img src="/img/blank.png" alt="home" id="projects_ico">Projects</a>
                    <ul class="submenu" style="display: none;">
                        <li><a href="/projects">Manage projects</a></li>
                        <li><a href="/projects/add.php" class="admin">Create a project</a></li>
                        <li></li>
                        <li><a href="/projects/submitted.php" class="admin client">Submitted projects</a></li>
                        <li><a href="/projects/closed.php" class="admin">Closed projects</a></li>
                    </ul>
                </li>
                <li class=""><a href="/my_account"><img src="/img/blank.png" alt="home" id="account_ico">Account</a>
                </li>
                <li class="active"><a href="/help.php"><img src="/img/blank.png" alt="help" id="help_ico">Help</a>
                </li>
            </ul>

        </div>
    </div>
</div>    
<div id="body" class="full">
  <div id="content">

    <!--start block-->
    <div class="block">
        <h1><img src="/img/blank.png" alt="home" id="help_ico"> Help</h1>
        <p>
        Curabitur blandit tempus porttitor. Cras mattis consectetur purus sit amet fermentum. Cras mattis consectetur purus sit amet fermentum. Aenean eu leo quam. Pellentesque ornare sem lacinia quam venenatis vestibulum. Maecenas faucibus mollis interdum. Maecenas sed diam eget risus varius blandit sit amet non magna.
        </p>
    </div>  
</div>   
</body>  

CSS:

* {
    margin:0;
    padding:0;
}
html, body {
    height:100%;
    font-family:Arial, Helvetica, sans-serif;
    font-size: 12px;
    line-height: 160%;
    position: relative;
    background: #000;
}
#sidebar{
    width: 200px;
    background: #000;
    height: 100%;
    padding-top: 30px;
    -webkit-box-shadow: inset -4px 0px 8px 0px rgba(0, 0, 0, 0.5);
        box-shadow: inset -4px 0px 8px 0px rgba(0, 0, 0, 0.5);
     float: left;
}
#body{
    float: left;
    padding: 30px 0 30px 40px;
    width: 75%;
}
TH1981
  • 3,105
  • 7
  • 42
  • 78

8 Answers8

74

Looks like you have float:left applied on your children. Use this code :

html, body {
    overflow: auto;
}
Ahmed Ashour
  • 5,179
  • 10
  • 35
  • 56
Tim Nguyen
  • 1,163
  • 10
  • 21
24

Please use this answer wisely, I't could help in many cases:

html, body{min-height:100%;}
body{height:100vh;}
11

try adding

body {
  min-height: 100%;
}
Hussein Negm
  • 551
  • 5
  • 17
9

When in doubt - the best way I found to tackle this is by adding:

html { overflow-y:scroll; }
Erick
  • 99
  • 1
  • 3
6

Not sure if this will help anyone but I had the same problem but only on mobile. I discovered that there was a style html { height: 100%; } that was causing the body to not extend the full height. Once I removed the 100% height on the html tag it fixed the body not extending the full height of the page on mobile. I still have 100% height on the body tag.

lflores
  • 3,770
  • 3
  • 19
  • 24
3

You seem to be trying to achieve a layout which spans the entire height of the container - these layouts are not posible. You should read up on the Faux Columns CSS technique, a common workaround to this problem.

Wex
  • 15,539
  • 10
  • 64
  • 107
2

There are two problems:

First:
The width of your elements is greater than 100% of the width of the page
This is why your div id="body" is getting stuck below the sidebar.

Try making the width of the body something like 30% and you should see what I mean.

Second:
height:100% does not really work the way it would seem there are workarounds for this.
Here is a great solution

Community
  • 1
  • 1
Malkus
  • 3,686
  • 2
  • 24
  • 39
  • I tried that, putting a clear inside the body and inside the `content` div and inside the `body` div and it had no effect – TH1981 Nov 11 '12 at 01:03
  • I had a chance to take a closer look at your code and updated my answer. take a look at let me know if that works for you. – Malkus Nov 11 '12 at 01:22
0

For me, I had to add margin-bottom: -2em to the container in my SPA where backend + frontend files meet

Dazzle
  • 2,880
  • 3
  • 25
  • 52