(I have attatched a picture of how the layout looks, the arrow shows where I want to move it to.) Hi, I am trying to position the green "leftnavbar" div both under the "header" div, and to the left of the "maincontent" div, but being new to CSS, am having a little trouble. Currently I created the "container" div, for the purpose of holding all the divs I plan to use on the page together. Currently all three divs ("header", "leftnavbar" and "maincontent" are children of the "container" div. I have tried nesting the "maincontent" div as a child of the "leftnavbar" div, but as the maincontent div is wider than leftnavbar, it has it's right side cutoff. I'm new to CSS, so this maybe a simple mistake, but I'm trying to keep my code proper and clean, so welcome any advice. Many thanks! My code: HTML: CSS:
try floating the navigation bar "left" and the content "right." Steelfrog is probably correct aswell with the padding, you've done maximum width, but then not taken into account the padding.
#leftnavbar { width: 25%; height: 200px; background-color: #33FF99; } #maincontent { float:left; width: 75%; height: 400px; background-color: #3399CC; } Try the above, afaik there's no need for position: relative; on anything at the moment with your layout. Also all you need to do is float the main container to the left, theres no need for the margin-left as you are having the left nav bar first. Also close left nav bar DIV before opening Main Content DIV. But I think when you progress with your layout your going to want to set a width on your sidebar and keep the main content fluid, and also want the main content to open before the left nav.
HI this will fix your problem. ----html code --- <body> <div id="container"> container <div id="header"> header </div> <div id="leftnavbar"> leftnavbar</div> <div id="maincontent"> maincontent </div> </div> </body> ---end of html code--- ----css--- body { background-color: #FF3333; } #container { margin:0px auto; width: 800px; height: 600px; padding: 5px; } #header { position: relative; width: 100%; background-color: #33ccff; } #leftnavbar { position: relative; width: 25%; height: 200px; background-color: #33FF99; float: left; } #maincontent { position: relative; margin-left: 25%; width: 75%; height: 400px; background-color: #3399CC; } ---css --