关于CSS选择器的问题
如果我有一个选择器,例如
#myTable tr td .someClass{....}
此 someClass 是否“仅”引用具有该类的 td 或者它是否引用具有“someClass”的 td 的任何子级?那么它与 ; 一样吗?
#myTable tr td.someClass{....}
基本上我的问题是 td 后面的空格有什么区别吗?
If I have a selector like
#myTable tr td .someClass{....}
Does this someClass refer "ONLY" to td having that class OR does it refer to any child of td having "someClass" ? So Is it same as ;
#myTable tr td.someClass{....}
Basically my question is does the space after td make any difference?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
#myTable tr td .someClass{....}
指的是 任何元素,其内部具有someClass
类 strong> 一个td
标记,位于tr
标记内,该标记位于 id 为myTable
的元素内。#myTable tr td.someClass{....}
引用带有someClass
类的td
标签,位于tr
标记内,该标记位于 id 为myTable
的元素内。#myTable tr td .someClass{....}
refers to any element with a class ofsomeClass
that is inside atd
tag, that is inside atr
tag, that is inside an element with an id ofmyTable
.#myTable tr td.someClass{....}
refers to atd
tag with a class ofsomeClass
, that is inside atr
tag, that is inside an element with an id ofmyTable
.是的,空间会有所不同:
Yes, the space makes a difference:
前一个选择器引用
someClass
类的元素,它是td
的后代。要引用类名
someClass
的td
元素,请使用后一个选择器。空格是一个后代选择器;如果您想要一个直接子元素(
td
和.someClass
元素之间没有元素),请使用>
:The former selector refers to an element of class
someClass
that's a descendant of atd
.To refer to a
td
element of class-namesomeClass
use the latter selector.The space is a descendent selector; if you want an immediate child (no elements between the
td
and the.someClass
element) use>
:孩子和父母之间有一个空间。如果没有空格,您将告诉 CSS 查找具有该类的元素。
A space separate children from parent. Without the space you are telling the CSS to find an element with that class instead.
是:
Yes:
空间确实有所作为。第一个选择器选择类
someClass
的任何元素,该元素是myTable
中tr
中td
的子元素。第二个选择任何具有
someClass
类的td
,该类是myTable
中tr
的子级The space does make a difference. The first selector selects any element with the class
someClass
that is a child of atd
in atr
inmyTable
.The second selects any
td
with the classsomeClass
that is a child of atr
inmyTable
td
后面的空格确实有所不同css:
html:
咖啡会呈现棕色,而酒红色。
The space after the
td
does make a differencecss:
html:
cofee will appear brown, and wine red.