HTML & CSS : ">" Greater than selector styles not applied

标签 html css css-selectors

我遇到了一个很奇怪的问题。根据我对 CSS“>”的理解,比选择器基本上只将样式应用于直接子项。但是我根本无法将样式应用于元素。奇怪的是,在检查元素时,我可以在 firebug 中看到其他 CSS 部分,但看不到应用的“>”样式。

我的 HTML 是:

<div id="navigation">
    <ul>
       <li><a href="#">First</a></li>
       <li><a href="#">Second</a></li>
       <li><a href="#">Third</a></li>
       <li><a href="#">Fourth</a></li>
    </ul>
</div>

CSS 部分是这样的:

/* Navigation */
#navigation {
    min-height:45px;
}

#navigation ul {
    list-style-type: none;
    margin: 0px 45px 0px 0px;
    font-weight: bold;
    border-left-width: 1px;
    border-left-style: solid;
    border-left-color: #F3F3F3;
}

#navigation ul li {
    margin: 0px;
    float: left;
    position: relative;
}

#navigation > ul > li {
    line-height: 26px;
    display: block;
}

#navigation > ul > li > a {
    border-right: 1px solid #F3F3F3;
    color: #333;
    display: block;
    font-family: 'Trebuchet MS';
    font-size: 15px;
    padding: 10px 18px 13px;
    position: relative;
    text-decoration: none;
    z-index: 1000;
}

#navigation > ul > li.current_page_item > a, 
#navigation > ul > li.current_page_parent > a, 
#navigation > ul > li.current_page_ancestor > a {
    border-top: 3px solid #72AC4B;
    color: #72AC4B;
    font-family: 'Trebuchet MS';
    margin-top: -3px;
}

所有其他样式都按正常方式应用,但根本无法识别使用“>”选择器的样式 block 。所以假设如果我检查 li 元素,我能够看到应用了以下样式:

#navigation ul li {
    margin: 0px;
    float: left;
    position: relative;
}

但我看不到应用以下样式:

#navigation > ul > li {
    line-height: 26px;
    display: block;
}

即使它是 ul 的直接子代。有没有人遇到过这个问题?可能是什么原因造成的?

最佳答案

假设您提供的 HTML 示例是您尝试将这些样式应用到的完整代码片段,我看不出会发生任何冲突以保证使用直接后代选择器 (>)。

整个过程只需使用子选择器即可。

/* Navigation */  
#navigation {
    min-height:45px;
}

#navigation ul {
    list-style-type: none;
    margin: 0px 45px 0px 0px;
    font-weight: bold;
    border-left-width: 1px;
    border-left-style: solid;
    border-left-color: #F3F3F3;
}

#navigation ul li {
    margin: 0px;
    float: left;
    position: relative;
    line-height: 26px;
    display: block;
}

#navigation ul li a {
    border-right: 1px solid #F3F3F3;
    color: #333;
    display: block;
    font-family: 'Trebuchet MS';
    font-size: 15px;
    padding: 10px 18px 13px;
    position: relative;
    text-decoration: none;
    z-index: 1000;
}

#navigation ul li.current_page_item a, 
#navigation ul li.current_page_parent a, 
#navigation ul li.current_page_ancestor a {
    border-top: 3px solid #72AC4B;
    color: #72AC4B;
    font-family: 'Trebuchet MS';
    margin-top: -3px;
}

关于HTML & CSS : ">" Greater than selector styles not applied,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12698333/

相关文章:

html - 使用 Go 服务器时 MIme 类型不正确

PHP - 在 HTML 文件中多次启动/结束 PHP

css - flex : 1的意义和好处

css - 悬停不起作用

jquery - CSS 和 jQuery : . name vs name^= (即类 vs "id arrays")

javascript - CSS :hover not working in chrome for delayed dynamically added classes

javascript - 从一个需要另一个 JavaScript 文件的函数调用

html - 在 html 标签中,单词被打破

javascript - 在不同文件中拆分文件(例如 html、图像、css、js 等)时,HTML 和 CSS 是否应保留在同一域中

html - 某些 UL 和 LI 标签的 CSS 样式