CSS选择顶级的ul [英] CSS to select top level of a ul

查看:181
本文介绍了CSS选择顶级的ul的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

li> ul> li 选择比 ul 的第一级更深的所有 li / p>

li 选择所有li元素



li:not(li> ul> li)应选择所有 li ul - 即只有第一级元素 - 但它不。为什么?



谢谢!

解决方案 li:not(li> ul> li)不工作是因为 li> ul> li



最简单的方法是获取最高级别​​是最简单的选择器(如Felix Kling在你的问题的意见中所说的)给最外层 ul 一个类或ID,然后执行:

  .ulClassNameOrID>但是,下面的内容也会得到你想要的( see fiddle ),因为它没有选择任何 ul 上一页 li (因此不是外部列表的子列表):

 :not(li)> ul> li {} 


li > ul > li selects all li elements which are deeper than the first level of a ul.

li selects all li elements

li:not(li > ul > li) should select all li elements which are no deeper than the first level of a ul--that is, only first level elements--but it doesn't. Why?

Thanks!

解决方案

The reason li:not(li > ul > li) does not work is because the li > ul > li is not a simple selector (as Felix Kling noted in the comments to your question).

The easiest way to get the top level is to give a class or id to the outer most ul and then do:

.ulClassNameOrID > li {}

However, the following gets what you desire also (see fiddle) as it does not select any ul that is a direct child of a previous li (so is not a sublist of the outer list):

:not(li) > ul > li {}

这篇关于CSS选择顶级的ul的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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