什么时候使用`>`sign in CSS? [英] When to use `>` sign in CSS?

查看:149
本文介绍了什么时候使用`>`sign in CSS?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

什么是“>


我遇到许多网站,的他们在他们的css文件中使用这种类型的符号来创建导航栏,如:

  #navigation ul li> ul {
/ *之间的一些代码* /
}

我省略> 符号为

  #navigation ul li ul { 
/ *之间的一些代码* /
}



有什么区别,什么时候使用> b

解决方案

> 表示选择器的直接子级,因此



li> a 只会匹配直接在< li> < a> 例如



如果html是< li>< span>< a>



删除> 将匹配嵌套在< li> 内的任何< a> ,因此 li a 会匹配
$ b中的< a>

< li>< a> ,但也在< li>< span>< a>

以下是有关直接子选择器的详细信息: https://developer.mozilla.org/en-US/docs/Web/CSS/Child_selectors


Possible Duplicate:
What does “>” mean in CSS rules?

I came across many many websites and I saw many of them use this type of notation in their css file for creating navigation bar like :

#navigation ul li > ul {
  /* some code in between */
}

but when i omit the > sign as

#navigation ul li ul {
  /* some code in between */
}

this still works the same way.

what is the difference and when to use > sign ?

解决方案

> Means the direct child of a selector, so

li > a will ONLY match an <a> which is directly inside an <li> for example.

If the html was <li><span><a> the <a> would not be matched.

Removing the > will match any <a> nested inside an <li>, irrespective of other things around it, so li a would match the <a> in

<li><a> but also in <li><span><a>, for example.

Here's more information on direct Child selectors: https://developer.mozilla.org/en-US/docs/Web/CSS/Child_selectors

这篇关于什么时候使用`&gt;`sign in CSS?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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