5

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.

grepsedawk
  • 3,324
  • 2
  • 26
  • 49

2 Answers2

7

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;
}
Community
  • 1
  • 1
Josh Crozier
  • 233,099
  • 56
  • 391
  • 304
  • any chance you could tell me if/how this could be implemented to solve [my similar question](http://stackoverflow.com/questions/23550856/multilevel-nav-menu-not-showing-3rd-level) about needing `overflow:hidden`but not wanting it?? – MilkyTech May 08 '14 at 22:16
  • @ChrisM I'll take a look at both of your questions – Josh Crozier May 08 '14 at 22:18
1

Clearfix will help

http://nicolasgallagher.com/micro-clearfix-hack/

http://jsfiddle.net/B6DSv/1/

.cf:before,
.cf:after {
    content: " "; /* 1 */
    display: table; /* 2 */
}

.cf:after {
    clear: both;
}

/**
 * For IE 6/7 only
 * Include this rule to trigger hasLayout and contain floats.
 */
.cf {
    *zoom: 1;
}
superUntitled
  • 22,351
  • 30
  • 83
  • 110