Need help on navigation sidebar and content CSS

时间:2015-10-30 23:45:19

标签: html css

Ok so on my webpage, I have a left navigation, the position if fixed and when i want to add my content on the index page, the content appears behind the navigation and does not start after it. If I remove the fixed position then it just goes underneath. Navigation CSS #nav { height: 100%; width: 18%; background-color: #1C1C1C; position: fixed; } I even tried putting all the content inside a div but no luck. Content DIV #padding { height: auto; position: absolute; right: 0; Screenshots

2 个答案:

答案 0 :(得分:2)

Just put your content inside a div: <div id="container"> <div id="nav"> <!-- your navbar markup --> </div> <div id="content"> <!-- your content --> </div> </div> with css you can style your elements: #container { width: 100%; } #nav { height: 100%; width: 18%; background-color: #1C1C1C; float: left; } #content { width: 82%; float: left; } With float: left your two divs appears aside. NOTE: If you don't want to put your content inside a div element, so just float your navbar element: #nav { height: 100%; width: 18%; background-color: #1C1C1C; float: left; } ...that's all and all following content appears (if possible) on the right side of your navbar.

答案 1 :(得分:0)

I would do margin-left:18%; or slightly higher on a container around your content. Then your content container will always be padded where the nav sits and will appear beside it.