html - 水平 float 元素在 chrome 中被向下推,但在 firefox 中没有

标签 html css google-chrome firefox

为什么子菜单中的最后一个列表项在 Chrome 中低于其余列表项,但在 Firefox 中却对齐?

JSFIDDLE字体变成红色以提高可见度

ACTUAL SITE

我已经尝试了所有我能想到的填充、边距、垂直对齐、最后一个子元素等。感到困惑。谢谢。

#hmenuWrapper {
    width: 100%;
}

#hmenu, #hmenu ul, #hmenu ul li, #hmenu ul li a {
    padding: 0;
    margin: 0;
    line-height: 1;
    font-family: 'Arial', sans-serif;
}

#hmenu:before, #hmenu:after, #hmenu > ul:before, #hmenu > ul:after {
    content: '';
    display: table;
}

#hmenu:after, #cssmenu > ul:after {
    clear: both;
}

#hmenu {
    position: relative;
    top: 0px;
    left: 180px;
    zoom: 1;
    height: 60px;
    width: 740px;
    background: url(../media/images/bottom-bg.png) repeat-x center bottom;
    border-radius: 2px;
}

#hmenu ul {
    background: url(../media/images/nav-bg.png) repeat-x 0px 4px;
    height: 69px;
}

#hmenu ul li {
    float: left;
    list-style: none;
}

#hmenu ul li a {
    display: block;
    height: 37px;
    padding: 17px 14px 0;
    margin: 4px 0px 0;
    border-radius: 2px 2px 0 0;
    text-decoration: none;
    font-size: 15px;
    color: white;
    text-shadow: 0 1px 1px rgba(0, 0, 0, .75);
    font-weight: 400;
    opacity: .9;
}

#hmenu ul li:first-child a {
    margin: 4px 0px 0 0;
}

#hmenu ul li:last-child {
    background-color: #168b09;
}

#hmenu ul li a:hover {
    background: url(../media/images/colorHover.png) center bottom;
    display: block;
    height: 37px;
    margin-top: 0px;
    padding-top: 20px;
    color: #616161;
    text-shadow: 0 1px 1px rgba(255, 255, 255, .35);
    opacity: 1;
}

#hmenu ul li.active a {
    background: url(../media/images/color.png) center bottom;
    display: block;
    height: 37px;
    margin-top: 0px;
    padding-top: 20px;
    color: #616161;
    text-shadow: 0 1px 1px rgba(255, 255, 255, .35);
    opacity: 1;
}



#nav-wrap {
    position: relative;
    left: 180px;
    top: -3px;
    zoom: 1;
    height: 40px;
    width: 740px;
    float: left;
    background: url(../media/images/colorinv.png);
}

#nav {
    display: inline;
    height: 40px;
    width: 100%;
}

#nav a:hover {
    color: #444444;
    text-decoration: none;
}

#nav li:hover {
    background: url(../media/images/nav-bginvHover.png);
}

    #nav a li:hover  {
        color: #444444;
    }


#nav ui li a {
    height: 40px;
    width: 185px;
}

.nav-item {
    float: left;
    height: 40px;
    line-height: 40px;
    text-align: center;
    text-decoration: none;
    width: 185px;
    list-style-type: none;
    color: white;
}

.nav-item a {
    height: 40px;
    width: 185px;
}

#nav li.nav-sel {
    float: left;
    height: 40px;
    line-height: 40px;
    text-align: center;
    width: 185px;
    list-style-type: none;
    color: white;
    font-family: 'Arial', sans-serif;
    background: url(../media/images/nav-bginv.png);
}

#nav li.nav-sel a {
    color: white;
    height: 40px;
    width: 185px;
    line-height: 40px;
}

最佳答案

#nav 中删除display: inline,不需要:https://jsfiddle.net/ry5mLkaL/1/

此外,您的 HTML 从第 42 行开始无效。您不应该用 anchor (或任何东西)包裹列表项。 anchor 应在列表项内。

 <ul id="nav">
    <a href="pages/companyServices.html"><li class="nav-item">Company Services</li></a>
    <a href="pages/skyAdvantages.html"><li class="nav-item">Sky Advantages</li></a>
    <a href="pages/customerRecognition.html"><li class="nav-item">Customer Recognition</li></a>
    <a href="pages/newsReleases.html"><li class="nav-item">News Releases</li></a>
 </ul>

<ul id="nav">
     <li class="nav-item"><a href="pages/companyServices.html">Company Services</a></li>
     <li class="nav-item"><a href="pages/skyAdvantages.html">Sky Advantages</a></li>
     <li class="nav-item"><a href="pages/customerRecognition.html">Customer Recognition</a></li>
     <li class="nav-item"><a href="pages/newsReleases.html">News Releases</a></li>
</ul>

关于html - 水平 float 元素在 chrome 中被向下推,但在 firefox 中没有,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37122107/

相关文章:

google-chrome - 持久保存 chrome devtools 设置

javascript - JS elementFromPoint 获取检索到的元素下方的元素

javascript - Markdown 解析器应该是客户端还是服务器端

html - 如何从最后一行的元素中删除边框?

javascript - 使用 jQuery 验证 keyup 上的表单输入

javascript - 垂直菜单与 Masonry 的奇怪行为

javascript - IE和chrome在发送XMLHTTPRequest之前不会执行js代码,直到收到该请求的响应

css - 表格没有清除自己的默认值?

javascript - 如何在用户控制时禁用 <a onclick>

google-chrome - Chrome/PC 中的 HTML5 视频