CSS CSS中的点是什么意思?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12811149/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What does the dot mean in CSS?
提问by code-gijoe
Can someone explain the difference for these two CSS selectors?
有人可以解释这两个 CSS 选择器的区别吗?
.work-container . h3 {
font-size: 14px;
margin-top: 0px;
font-weight: 600;
height: 27px;
}
What is the extra dot in the upper definition?
上定义中的额外点是什么?
.work-container h3 {
font-size: 14px;
margin-top: 0px;
font-weight: 600;
height: 27px;
}
采纳答案by BoltClock
A .prefix usually represents a class selector, but if it's immediately followed by whitespace then it's a syntax error.
一个.前缀通常代表一类选择,但如果它紧跟空格那么它是一个语法错误。
If I were to hazard a guess, then it's likely the author meant to say .work-container > h3, but missed the Shift key just as he was about to type the >character (the child combinator).
如果我要冒险猜测,那么作者很可能想说.work-container > h3,但在他即将键入>字符(子组合器)时错过了 Shift 键。
Your second selector, .work-container h3, simply means any h3that's contained within an element with a class called work-container.
您的第二个选择器 ,.work-container h3仅表示h3包含在具有名为 的类的元素中的任何选择器work-container。
回答by Jobin
Cases
案例
Selector start with dot
.class_namesignifies class nameTwo doted selector separated by space
.outside.insidemeans element with
.insideclass descended from an element with class.outsideTwo doted selector without separation
.name1.name2means element that has both class
name1andname2eg:class="name1 name2"
选择器以点开头
.class_name表示类名两个用空格隔开的点选选择器
.outside.inside表示具有
.inside类的元素从具有类的元素派生而来.outside没有分离的两个宠爱选择器
.name1.name2表示同时具有 class
name1和name2eg 的元素:class="name1 name2"
Related questions:
相关问题:
回答by Praveen Kumar Purushothaman
.in CSS means it is a class and it can be applied to many elements.
.在 CSS 中意味着它是一个类,它可以应用于许多元素。
#in CSS means it is an ID and it can be applied to one element per page.
#在 CSS 中表示它是一个 ID,它可以应用于每页一个元素。
Without the either, it is a tag, targeting all the usage.
没有两者,它就是一个标签,针对所有用途。
In your syntax, .work-container . h3is actually error. The .should have been either ,or as BoltClocksaid, >, which says the direct descendant operator in CSS.
在您的语法中,.work-container . h3实际上是错误。本.应该是要么,或BoltClock说>,它说,在CSS的嫡系操作。
回答by dotNETbeginner
.says its class
.说它的类
#means its an id
#意味着它的一个 id
and if there is nothing but the selector, then it is a tag
如果只有选择器,那么它就是一个标签
回答by Santosh Kori
.in CSS means it is a class & it can be applied to many elements with use space between classes
.在 CSS 中意味着它是一个类 & 它可以应用于许多元素,并在类之间使用空间
For example:
例如:
<h3 class="class1 class2 class2">Heading</h3>
#in CSS means it is an ID and it can be applied to one element per page.
#在 CSS 中表示它是一个 ID,它可以应用于每页一个元素。
For example
例如
<h3 id="idname1">Heading</h3>

