调整窗口大小可使制表符转到下一行

问题描述

| 这是我的CSS和HTML
#header {
    position: absolute;
    left: 0;
    right: 0;
    top: 0;
    background-image: url(\'/public/images/header.png\');
    background-repeat: repeat-x;
}

#nav {
    background: transparent;
    height: 2.5em;
    left: -25px;
    list-style: none;
    margin: 1em 0 1em;
    min-width: 100%;
    min-height: 100%;
    overflow: hidden;
    padding: 60px 0 30px 0;
}

#nav a {
    color: white;
    display: block;
    float: left;
    height: 2.5em;
    padding-left: 30px;
    text-decoration: none;
    padding-right: 30px;
    text-shadow: 0.1em 0.1em #333;
}

#nav a:hover {
    text-shadow: 0.1em 0.1em white;
    background-color: white;
    color: darkred;
    padding-bottom: 5px;
    text-shadow: 0.1em 0.1em lightgray;
}

#nav a:hover.active,#nav a.active {
    background-color: white;
    background-position: 0 -60px;
    color: darkred;
    text-shadow: 0.1em 0.1em lightgray;
    padding-bottom: 5px;
}

#nav li {
    float: left;
    margin: 0 8px 0 0;
 /* Spacing between tabs */;
}

#nav span {
    cursor: pointer;
    display: block;
    float: left;
    line-height: 1.5em;
    padding: .5em 5px 0 0;
}


<div id=\"header\">
    <div id=\"navigation\">
        <ol id=\"nav\">
            <li><a id=\"overview\" href=\"/overview\"><span>Overview</span></a></li>
            <li><a id=\"analysis\" href=\"/overview\" class=\"active\"><span>Analysis</span></a></li>
            <li><a id=\"dashboard\" href=\"/dashboard\"><span>My Dashboard</span></a></li>
            <li><a id=\"preferences\" href=\"/overview\"><span>Preferences</span></a></li>
            <li><a id=\"contact\" href=\"/overview\"><span>Contact</span></a></li>
            <li><a id=\"logout\" href=\"/overview\"><span>Sign In</span></a></li>
        </ol>
    </div>
</div>
这在我的屏幕上看起来不错,但是如果我开始调整窗口大小,则会使选项卡跳转并转到下一行。我发现在其他带有标签的网站上并非如此。我在这里做错了什么?谢谢。     

解决方法

这些\“其他站点\”可能将它们的ѭ1包含在另一个元素(例如ѭ2)中,并通过CSS设置了显式宽度,例如
width: 960px
: 请参阅:http://jsfiddle.net/mBJQN/
<div id=\"container\">
    YOUR HTML HERE
</div>

#container {
    width: 960px;
    position: relative
}
我加了
position: relative
,使
#header
上的
position: absolute
相对于
#container
(请参阅此处)。 这里还有另一种选择,但可能不是您所追求的。 您可以将
white-space: nowrap
加到
#header
,然后从
float
更改为
display: inline-block
。如果这是您想要的选项,请告诉我,因为它需要更多的工作。 http://jsfiddle.net/mBJQN/1/