Using :after CSS selector to fill a space?

css, css-selectors

Solution

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 */
}

Problem

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 &#038; 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

Original source