CSS:为什么当我取出 Overflow:hidden 时会出现这种情况?

发布于 2024-11-29 20:23:44 字数 247 浏览 3 评论 0原文

因此,在类导航中,当我有溢出:隐藏时,那里有中心并且效果很好,但我不能使用溢出:隐藏,因为它会隐藏导航中的下拉菜单。

但是当我把它拿出来的时候,它就碎了?除了overflow:hidden之外,我还能使用什么来保持它看起来正确,并且不隐藏我的导航?

http://jsfiddle.net/xtian/svr8C/1/

So in the class nav, when i have overflow:hidden in there is centers and works well, but i can't use overflow:hidden because it will hide my drop downs in the navigation.

But when i take it out, it breaks it? What else can I use other than overflow:hidden to keep it looking right, and not hide my navigation?

http://jsfiddle.net/xtian/svr8C/1/

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

若有似无的小暗淡 2024-12-06 20:23:44

只需设置 .nav 的高度(35px?)并删除 overflow: hide;

Just set the height (35px?) of .nav and remove the overflow: hidden;

北风几吹夏 2024-12-06 20:23:44

它导致overlfow隐藏清除所有浮动并赋予元素浮动li的高度。解决方案是这样的: http://jsfiddle.net/svr8C/11/

这条语句:

.nav:after{clear:both;display:block;visibility:hidden;overflow:hidden;height:0 !important;line-height:0;font-size:xx-large;content:" x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x ";}

添加一个lis 之后的不可见元素并清除它们。它取自著名的 oocss 媒体元素:https://github。 com/stubbornella/oocss/blob/master/core/media/media.css

Its cause the overlfow hidden clear all the float and gives the element the height of the floating li. The solution is this: http://jsfiddle.net/svr8C/11/

This statement:

.nav:after{clear:both;display:block;visibility:hidden;overflow:hidden;height:0 !important;line-height:0;font-size:xx-large;content:" x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x ";}

adds an invisible element after the lis and clear them. Its taken from the famous oocss media element: https://github.com/stubbornella/oocss/blob/master/core/media/media.css

不离久伴 2024-12-06 20:23:44

尝试溢出:自动; - 这将清除浮动,类似于溢出:隐藏;但如果你不小心,可能会引入滚动条。或者,您可以尝试“全部浮动”方法:另一个浮动元素内的浮动元素也会强制清除浮动。

Try overflow: auto; - this will clear the float similarly to overflow: hidden; but may introduce scrollbars instead if you're not careful. Alternatively you can try a "float all" approach: a floated element inside another floated element also forces float clearing.

祁梦 2024-12-06 20:23:44

您可以使用此类内容。

HTML:

<ul class="menu">
    <li><a href="#">Testing</a></li>
    <li><a href="#">Testing</a>
        <ul class="submenu">
            <li><a href="#">Testing</a></li>
            <li><a href="#">Testing</a></li>
            <li><a href="#">Testing</a></li>
            <li><a href="#">Testing</a></li>
        </ul>
    </li>
    <li><a href="#">Testing</a></li>
    <li><a href="#">Testing</a></li>
</ul>

CSS:

.menu li {
    display: inline-block;
}

.menu li a {
    color: #fff;
    background: orangered;
    text-decoration: none;
    padding: 0.5em;
    border-bottom: 5px solid #000;
}

.menu li .submenu {
    display: none;
}

.menu li:hover > .submenu {
    display: block;
    position: absolute;
    top: 30px;
}

.menu li .submenu li {
    display: block;
    margin-top: 20px;
}

这是演示

You can user something of this sort.

HTML:

<ul class="menu">
    <li><a href="#">Testing</a></li>
    <li><a href="#">Testing</a>
        <ul class="submenu">
            <li><a href="#">Testing</a></li>
            <li><a href="#">Testing</a></li>
            <li><a href="#">Testing</a></li>
            <li><a href="#">Testing</a></li>
        </ul>
    </li>
    <li><a href="#">Testing</a></li>
    <li><a href="#">Testing</a></li>
</ul>

CSS:

.menu li {
    display: inline-block;
}

.menu li a {
    color: #fff;
    background: orangered;
    text-decoration: none;
    padding: 0.5em;
    border-bottom: 5px solid #000;
}

.menu li .submenu {
    display: none;
}

.menu li:hover > .submenu {
    display: block;
    position: absolute;
    top: 30px;
}

.menu li .submenu li {
    display: block;
    margin-top: 20px;
}

Here is the demo

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文