Skip to content Skip to sidebar Skip to footer

Make Navigation Bar Take Up Entire Page Height In Css

I am designing a website using css and html. I have managed to get a navigation bar on the left side of my page using this css, however when the screen is scrolled down the naviga

Solution 1:

100% does not apply because it is floated. Change the parent container to position: relative and the navbar to position: absolute will solve the problem.

#container{
    position: relative;
}

#navbar {
    background: #a8a599;
    /*float: left; Instead of float, use absolute position*/position: absolute;
    width: 20%;
    height: 100%;
}

Demo

Solution 2:

Using only HTML and CSS you can usually fix this 100% height issue by using:

body,html{
   height:100%;
}

If you want to use the JavaScript method then this should work

document.getElementById("navbar").style.height=window.innerHeight;

That will set the height of the navBar element to whatever the height of the browser window is

Solution 3:

It took my like 2 hours but I finally found solution to this! Accepted answer by Derek almost work but as my comment suggests, not entirely. When your left bar has more content then main bar, left menu wont stretch up to the height of its content. You maybe never get so many options in that menu but I am building new administration wich will have many modules in future and you never know if it can happen or not.

Solutions are old good tables! Dont worry, not quite. Only css display property with value of table, table-row and table-column:

Basic idea:

#page {
    display: table;
    min-height: 100%;
    width: 100%;
}
#pageRow {
    display: table-row;
}
#leftMenu {
    display: table-cell;
    width: 300px;
    background-color: red;
}
#content {
    display: table-cell;
    background-color: blue;
}
  1. little content in both sections http://jsfiddle.net/85w56gkx/1/

  2. more content in left menu section http://jsfiddle.net/1o92r7ao/

  3. more content in main content section http://jsfiddle.net/Ldav83vn/

Solution 4:

If you plan to have the navBar fixed you can do something along the lines of Fiddle

*{
    margin:0;padding:0;
}
#navBar {
    background: red;
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    width: 100px;
}
#content {
    background: yellow;
    min-height:1000px;
    display: block;
    margin-left: 100px; /*width of nav bar*/
}

Solution 5:

You could just modify your #navbar css and set position to fixed

#navbar {
  background: #a8a599;

  /* removed css *//* float: left; *//* new css */position:fixed;
  top:0;
  left:0;
  /***********/width: 20%;
  height: 100%;
}

float: left; is positioned in relation to the document.

Removing float and adding position: fixed; will position the element in relation to the window.

Then you can add top, bottom, left or right to suit your needs

I forked your fiddle for an example Here

Some more information on floatW3 CSS Float

Some more information on positionW3 CSS Position

Post a Comment for "Make Navigation Bar Take Up Entire Page Height In Css"