From 33058f2b292b3a581333bdfb21b8f671898c5060 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:40:17 -0500 Subject: initial commit --- files/zh-cn/web/css/class_selectors/index.html | 123 +++++++++++++++++++++++++ 1 file changed, 123 insertions(+) create mode 100644 files/zh-cn/web/css/class_selectors/index.html (limited to 'files/zh-cn/web/css/class_selectors/index.html') diff --git a/files/zh-cn/web/css/class_selectors/index.html b/files/zh-cn/web/css/class_selectors/index.html new file mode 100644 index 0000000000..13fd848a89 --- /dev/null +++ b/files/zh-cn/web/css/class_selectors/index.html @@ -0,0 +1,123 @@ +--- +title: 类选择器 +slug: Web/CSS/Class_selectors +tags: + - CSS + - Selectors +translation_of: Web/CSS/Class_selectors +--- +
{{ CSSRef() }}
+ +

概述

+ +

在一个HTML文档中,CSS类选择器会根据元素的类属性中的内容匹配元素。类属性被定义为一个以空格分隔的列表项,在这组类名中,必须有一项与类选择器中的类名完全匹配,此条样式声明才会生效。

+ +

语法

+ +
.类名 {样式声明 }
+ +

注意它与下面的语句等价  {{ Cssxref("Attribute_selectors", "attribute selector") }}:

+ +
[class~=类名] {样式声明 }
+ +

示例

+ +
span.classy {
+  background-color: DodgerBlue;
+}
+
+ +

上面的CSS作用于下面的HTML代码:

+ +
  <span class="classy">Here's a span with some text.</span>
+  <span>Here's another.</span>
+
+ +

则会产生这样的效果:

+ +

Here's a span with some text.

+ +

Here's another.

+ +

规范

+ + + + + + + + + + + + + + + + + + + + + + + + + + +
SpecificationStatusComment
CSS Selectors Level 3{{ Spec2('CSS3 Selectors') }} 
CSS 2.1{{ Spec2('CSS2.1') }} 
CSS 1{{ Spec2('CSS1') }} 
+ +

浏览器兼容性

+ +

{{ CompatibilityTable() }}

+ +
+ + + + + + + + + + + + + + + + + + + +
FeatureChromeFirefox (Gecko)Internet ExplorerOperaSafari
Basic support{{ CompatVersionUnknown() }}{{ CompatVersionUnknown() }}{{ CompatVersionUnknown() }}{{ CompatVersionUnknown() }}{{ CompatVersionUnknown() }}
+
+ +
+ + + + + + + + + + + + + + + + + + + + + +
FeatureAndroidChrome for AndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
Basic support{{ CompatUnknown() }}{{ CompatUnknown() }}{{ CompatUnknown() }}{{ CompatUnknown() }}{{ CompatUnknown() }}{{ CompatUnknown() }}
+
+ +

See also

-- cgit v1.2.3-54-g00ecf