Overflow of hidden hides is hidden, but overflow is hidden hiding the navigation background

First of all, here is the .js fiddle: http://jsfiddle.net/B6DSv/

The problem I encountered is related to 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 shoot overflow: hidden;, the dropdown menu works ... But my background is shot.

+4
source share
2 answers

As the child elements are moved (unloaded from the document flow), the parent element navcollapses by itself; Thus, the background is not displayed because it navhas a height 0.

Instead of using overflow:hiddento fix this, just add clearfix to the element:

nav:after {
    content:'';
    clear:both;
    display:table;
}
+6

Clearfix

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;
}
+1

Source: https://habr.com/ru/post/1539821/


All Articles