On this page I wish to have the entire space to the right of the navigation filled in white.
So, I achieved 5px wide white block using the :after CSS selector, and am hoping there is a way to make it fit the available width, although I am open to other suggestions!:
#menu-main-menu:after {
content:"";
display:block;
background:#fff;
width:5px;
height:30px;
float:right;
}
Here is the simplified HTML:
<div class="menu"><ul id="menu-main-menu">
<li><a href="#">Home</a></li>
<li><a href="#">About us</a></li>
<li><a href="#">Courses & prices</a></li>
<li><a href="#">Activities in Rio</a></li>
<li><a href="#">Accommodation</a></li>
<li><a href="#">News</a></li>
<li><a href="#">FAQs</a></li>
<li><a href="#">Contact</a></li>
</ul>
</div>
And all the relevant CSS:
#primary-menu ul {
overflow:hidden;
}
#primary-menu li {
list-style:none;
float:left;
}
#primary-menu a {
color:#333;
background: #fff;
display:block;
}
#primary-menu .current-menu-item a, #primary-menu .current-page-parent a {
color:#fff;
background:none;
}
#menu-main-menu:before {
content:"";
display:block;
background:#fff;
width:20px;
height:30px;
float:left;
}
#menu-main-menu:after {
content:"";
display:block;
background:#fff;
width:5px;
height:30px;
float:right;
}
Thanks for taking the time to check out my question!
Caroline
You could add the ::after
pseudo selector to the li.current-menu-item
instead of #menu-main-menu
and add white background from that element onwards.
.current-menu-item:after {
background: none repeat scroll 0 0 #fff;
content: "";
height: 30px;
position: absolute;
right: -1000px; /* these numbers are the same */
top: 0;
width: 1000px; /* and need to be at least the width of the menu */
}
#primary-menu li {
position: relative; /* position the ::after element relative to the li */
}
#primary-menu ul {
....
overflow: hidden; /* you already have this to clear your floats */
.... /* but I thought I should emphasise that you need it */
}
The example below works by adding an extra li
to fill, but since the font will render dirrentely among browsers you cannot predict the width. The workaround in this example creates a container (#cen
) for centering the content and setting the width, also the overflow
property is set to hidden. Doing this you are able to add a significantly bigger div
wrapping the ul
and the filler li
with a lot more width than required. Which causes no problem since the parent.parent is hidding overflows.
http://jsfiddle.net/efortis/3YpDh/1/
<div id="cen">
<div class="menu">
<ul id="menu-main-menu">
<li><a href="#">Home</a></li>
<li><a href="#">About us</a></li>
<li><a href="#">Courses & prices</a></li>
<li><a href="#">Activities in Rio</a></li>
<li><a href="#">Accommodation</a></li>
<li><a href="#">News</a></li>
<li><a href="#">FAQs</a></li>
<li><a href="#">Contact</a></li>
<li class="filler"> </li>
</ul>
</div>
</div>
#cen {
width: 960px;
margin: 0 auto;
overflow: hidden;
}
.menu {
width: 1200px;
float:left;
}
li {
padding: 10px 25px;
float:left;
background: white;
}
.filler {
width: 200px;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With