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 navigation bar no longer continues.
#navbar {
background: #a8a599;
float: left;
width: 20%;
height: 100%;
}
However i would like to make the height of the navigation bar the height of the document. I feel like i might need java script for this, however i am new to java-script, so i am not sure how i would accomplish this. I thought making the height 100% would make it take up the whole page, owever it only takes up the visible part of the page.
Here it is on fiddle if you want to look at the rest of the page http://jsfiddle.net/HRpXV/3/embedded/result/
100%
does not apply because it is floated. Change the parent container toposition: relative
and the navbar toposition: absolute
will solve the problem.Demo
Using only HTML and CSS you can usually fix this 100% height issue by using:
If you want to use the JavaScript method then this should work
That will set the height of the navBar element to whatever the height of the browser window is
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:
little content in both sections http://jsfiddle.net/85w56gkx/1/
more content in left menu section http://jsfiddle.net/1o92r7ao/
more content in main content section http://jsfiddle.net/Ldav83vn/
If you plan to have the navBar fixed you can do something along the lines of Fiddle
You could just modify your
#navbar
css and set position to fixedfloat: 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
float
W3 CSS FloatSome more information on
position
W3 CSS Position