css为第一个直接子项 [英] css for the first direct child only

查看:141
本文介绍了css为第一个直接子项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下html结构:

I have the following html structure:

<div class="nav-collapse">
              <ul class="nav">

              </ul>

              <ul id="registerCart" class="nav pull-right">

              </ul>

</div>

,我想将以下规则仅应用于第一个导航, >

and I wanted to apply the following rule only to the first nav, so I did:

.nav-collapse > .nav {
    left: 135px;
}

但是这也适用于registerCart。

however this is applying to the registerCart as well. How do I apply this only to the first nav?

推荐答案

使用第一个子选择器:

.nav-collapse .nav:first-child {}

如果您有更多嵌套的 .nav 元素,您可以将其与直接子选择器组合。

You can combine it with the direct child selector if you have more nested .nav elements.

.nav-collapse > .nav:first-child {}

这篇关于css为第一个直接子项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆