html - IE8 忽略 li 标签的宽度

标签 html css internet-explorer-8

我有一个似乎是菜鸟问题,但我无法以我的眼光解决这个问题。我真的需要另一双眼睛来帮助我了解为什么 li 标签没有在 IE8 中渲染宽度。

虽然其他浏览器如chrome和firefox渲染样式都很好,但IE8拒绝配合,拒绝将每个li的宽度设置为108px。

这是 HTML:

<div id="navigation">
<ul>
    <li><a href="">HOME</a></li>
    <li><a href="">SERVICES</a></li>
    <li class="current_tab"><a href="">COMPANY</a></li>
    <li><a href="">EMPLOYEE</a></li>
    <li><a href="">WORK TOOLS</a></li>
    <li><a href="">CONTACT</a></li>
</ul>

这是该导航以及父标签的 CSS:

body, html {
    overflow: auto;
    position: relative;
}

h3 {
    margin-bottom: 10px;
}

#employee_dir {
    margin-bottom: 20px;
}

#lotus {
    padding-top: 20px;
}

#content {
    margin-top: 10px;
}

#navigation li{
    background-color: transparent;
    background: url('../img/off-tab.png') no-repeat;
    padding-top: 0px !important;
    width: 108px !important;
    padding: 0px;
}

.current_tab {
    background-color: transparent;
    background: url('../img/on-tab.png') no-repeat !important;
    width: 108px;
    height: 33px !important;
}

#navigation a {
    text-align: center;
}

我还附上了一些我所看到的屏幕截图。

This is IE8 showing the css using the dev tools built in the browser However, this is what it renders for the li tag This is how the nav renders in IE8 However this is how it renders in chrome

最佳答案

不要使用!important声明,而是尝试制作 <li>inline-block

#navigation li{
    background-color: transparent;
    background: url('../img/off-tab.png') no-repeat;
    padding-top: 0px !important;   <------ Why padding here?
    width: 108px;
    padding: 0px;   <-------Your padding-top gets re-setted here
    display: inline-block;  <------- Here
}

关于html - IE8 忽略 li 标签的宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13216995/

相关文章:

html - 当内部元素的字体大小发生变化时,IE 出现文本缩进问题

html - CSS 没有加载到 Firefox 中?

jQuery 在元素之前和之后更改背景颜色框

javascript - EmberData unloadAll 不适用于 IE8。适用于 Chrome/FireFox

javascript - IE8 显示位置 .css 错误,但 Chrome 没问题

javascript - 如何使用jquery选择数组中的多个输入值

javascript - Jquery:window.unload 不适用于 chrome 72.0.3626.109

html - 单独更改部分div

javascript - 如何让 metisMenu 在鼠标悬停时自动展开?

javascript - 为什么在 IE8 中禁用日期不能与 Jquery 日期选择器一起正常工作