在CSS文件中使用空格 [英] usage of spaces in CSS files
问题描述
这个问题必须是最基本的问题,但我不清楚,所以我想问一下:
假设你有一些基本的HTML像这样:
< div class =a>
< p class =b>某物< / p>
< img class =b>
< p class =c>某物< / p>
< / div>
如何选择第一个< p>
元素使用CSS?
我之所以感到迷惑,直到现在我相信CSS可以通过指定类型和上课,但似乎我做不到。所以我可以有这样的: div p
或 div .b
或 .ap
或 .a .b
但不是 div .ap .b
,因为我相信以及如何每个浏览器工具都会命名这些元素(比如 div.a pb
)
是因为类和类型之间的空间是什么?
类和类型之间的空间是什么?
是的,空格是一个后代选择器。
ab
表示元素类型 a
和类 b
。
a .b
表示 a * .b
表示元素任何类型和类 b
,它是类型为 a
的元素的后代。
This one has to be the most basic question but it's not clear in my mind, so I'd like to ask it:
Say you have some basic HTML like this:
<div class="a">
<p class="b">something</p>
<img class="b">
<p class="c">something</p>
</div>
How can you select the first <p>
element using CSS?
The reason why I'm puzzled that up till now I believed that CSS can work by both specifying type and class, but it seems I cannot do it. So I can have something like: div p
or div .b
or .a p
or .a .b
but not div .a p .b
as I was believing and as how every browser tool names the elements (like div.a p.b
)
Is all this issue because of the space between the class and the type?
Is all this issue because of the space between the class and the type?
Yes, a space is a descendent selector.
a.b
means "An element of type a
and class b
".
a .b
means a *.b
means "An element of any type and class b
that is a descendent of an element of type a
.
这篇关于在CSS文件中使用空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!