Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Overflow hidden hides dropdown, but taking overflow hidden off hide navigation background

Tags:

html

css

First off, here's a .js fiddle: http://jsfiddle.net/B6DSv/

The issue I am having is with my .css:

nav {
    overflow: hidden; /*THIS LINE*/
    background-color: #004b98;
    width: 100%;
    margin: 0;
    padding: 0;
}

and here:

<nav>
    <ul>
        <li><a href="index.html">Home</a>
            <ul>
                <li><a href="#">teadsfasdfadsst</a></li>
            </ul>
        </li>

        <li><a href="#">Gallery</a></li>
        <li><a href="#">Map</a></li>
    </ul>
</nav>

If I take off overflow: hidden;, the dropdown works... But my background is taken off.

like image 255
grepsedawk Avatar asked Mar 20 '23 16:03

grepsedawk


1 Answers

Since the children elements are floated (taken out of the document flow), the parent element, nav, collapses upon itself; thus, the background isn't shown because nav has a height of 0.

Rather than using overflow:hidden to fix this, just add a clearfix to the element instead:

Updated Example

nav:after {
    content:'';
    clear:both;
    display:table;
}
like image 140
Josh Crozier Avatar answered Apr 06 '23 14:04

Josh Crozier