隐藏溢出隐藏下拉菜单,但隐藏隐藏隐藏导航背景 [英] Overflow hidden hides dropdown, but taking overflow hidden off hide navigation background
问题描述
首先,这是一个.js小提琴: http://jsfiddle.net/B6DSv/ >
.css是我遇到的问题:
nav {溢出:隐藏;/*这条线*/背景颜色:#004b98;宽度:100%;边距:0;填充:0;}
在这里:
< nav>< ul>< li>< a href ="index.html"> Home</a>< ul>< li>< a href =#"> teadsfasdfadsst</a></li></ul></li>< li>< a href =#">图库</a></li>< li>< a href =#"> Map</a></li></ul></nav>
如果我起飞 overflow:hidden;
,则该下拉列表有效...但是我的背景被取消了.
由于子元素是浮动的(从文档流中取出),因此父元素 nav
自身折叠;因此,由于 nav
的高度为 0
.
而不是使用 overflow:hidden
来解决此问题,只需添加 clearfix 替换为元素:
nav:之后{内容:'';清除:两者;显示:表;}
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.
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:
nav:after {
content:'';
clear:both;
display:table;
}
这篇关于隐藏溢出隐藏下拉菜单,但隐藏隐藏隐藏导航背景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!