CSS >(选择器)不工作

标签 css css-selectors

为什么这段代码不起作用?只有 #menu 中第一个 ul 中的 li 元素应该是红色的。

.l-branding .l-region #menu > ul li {background: red;}

最佳答案

Only the li items in the first ul in the #menu should be red.

然后你需要使用:first-of-type:first-child使第一个 ul 变为红色的选择器:

.l-branding .l-region #menu > ul:first-of-type li {background: red;}

演示:https://jsfiddle.net/o1muekkj/

关于CSS >(选择器)不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34319689/

相关文章:

html - chrome 上的宽度错误

html - 如何在引导移动模式下垂直居中列?

html - flex 盒元素内固定元素的宽度

html - 使用 CSS,如何通过其类修改子元素而不影响具有相同类但父级略有不同的另一个子元素

css - 使用@font-face 打印网页

css - 无法获取 css 表格数据以卡住第一列

html - 结合 :nth-child with :not() selectors

CSS :not([class* ="hidden"]):nth-of-type(4n+1) not working

python - Python Selenium 中带有 ng-model 的下拉选择

CSS 规则,前所未见