首页 > 解决方案 > HTML5新手Q | nav > ul VS nav ul / 有什么区别?

问题描述

我只是想知道,在 CSS3 中,当我们输入示例时:

nav > ul{
    margin: 0px;
}

这意味着 nav 元素内的 ul 边距将为 0px。好的。

但!这是什么意思 ?nav > ul 有什么区别?!:

nav ul{
    margin: 0px;
}

另外,小问题要完成: nav 的目的是什么?我们可以在没有它的情况下制作导航菜单。

谢谢,

技术。

标签: htmlcss

解决方案


对于“nav > ul”的情况,ul 是 nav 的子代,而对于“nav ul”的情况,ul 是 nav 的后代。

例如:

<div class="first">
    <p></p>
    <p></p>
    <p></p>
    <p></p>
    <div class="second">
          <p></p>
    </div> 
</div>

.first p {
    /*** This will target all the <p> elements in the HTML above ***/
}

.first > p {
    /*** This will target all <p> elements except the one nested within the "second" class ***/
}

来源:https ://teamtreehouse.com/community/difference-between-descendant-and-child-selectors


推荐阅读