在CSS文件中使用空格 [英] usage of spaces in CSS files

查看:117
本文介绍了在CSS文件中使用空格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题必须是最基本的问题,但我不清楚,所以我想问一下:

假设你有一些基本的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 .bbut 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屋!

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