I am trying to create a solution for a website that I am working on, in which the menus and submenus are horizontal, but the divs expand to the full width of the page.
First of all, here is an example HTML:
<div id="menu-container" class="full-width"> <nav id="nav1" class="normal-width"> <ul class="main-menu"> <li id="item1"> <a href="#">item 1</a> <ul class="sub-menu"> <li id="item11"> <a href="#">item 1.1</a> </li> <li id="item12"> <a href="#">item 1.2</a> </li> <li id="item13"> <a href="#">item 1.3</a> </li> </ul> </li> <li id="item2"> <a href="#">item 2</a> <ul class="sub-menu"> <li id="item21"> <a href="#">item 2.1</a> </li> <li id="item22"> <a href="#">item 2.2</a> </li> </ul> </li> <li id="item3"> <a href="#">item 3</a> </li> </ul> </nav> </div>
CSS for this menu:
.full-width { width: 100%; } .normal-width { width: 1024px; margin: 0 auto 0 auto; } a { color: black; text-decoration: none; } .clear { clear: both; } .main-menu { list-style-type: none; margin: 0; padding: 0; position: relative; background-color: red; } .main-menu > li { float:left; margin-right:2em; } .sub-menu { list-style-type: none; margin: 0; padding: 0; display:none; background-color: orange; } .sub-menu li { float:left; margin-right:2em; } .main-menu > li.selected { background-color:orange; } .main-menu > li.selected .sub-menu { display:block; position:absolute; left:0; right:0; }
And related to jQuery:
// Add a clear div to allow adding background color to main-menu $(".main-menu").append("<div class='clear'></div>"); // Make the first class selected $(".main-menu > li:first").addClass("selected"); // Switch the selected class $(".main-menu > li").click(function() { $(".selected").removeClass("selected"); $(this).addClass("selected"); }); // Disable menu links $(".main-menu > li > a").click(function(e) { e.preventDefault(); });
Everything is nice and dandy, and the right horizontal menu is created. What I'm struggling with, and I canโt create what you can see in this picture: 
Pay attention to the following image:
The thick black border around the image is the full size and width of the web page (i.e. the border of the browser window)
The thin vertical purple lines in the middle are not visible, they are in the picture to show you where the content will be, i.e. no content will go to the far left or far right of the purple line
Top-level menu items have a red background
Submenus appear in the area with an orange background.
Now, to the problem:
Notice how the red and yellow backgrounds spread to the edges of the web page, but the elements of these pages appear inside the content area inside the purple lines . This is what I am trying to achieve, but I cannot. I cannot extend the background to the edges of the web browser (i.e. full page width). My solutoin centers the red and orange backgrounds in the middle.
source share