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/api/cssstylerule/index.html | 54 ++++++++++++++++++++++ .../web/api/cssstylerule/selectortext/index.html | 33 +++++++++++++ files/zh-cn/web/api/cssstylerule/style/index.html | 43 +++++++++++++++++ 3 files changed, 130 insertions(+) create mode 100644 files/zh-cn/web/api/cssstylerule/index.html create mode 100644 files/zh-cn/web/api/cssstylerule/selectortext/index.html create mode 100644 files/zh-cn/web/api/cssstylerule/style/index.html (limited to 'files/zh-cn/web/api/cssstylerule') diff --git a/files/zh-cn/web/api/cssstylerule/index.html b/files/zh-cn/web/api/cssstylerule/index.html new file mode 100644 index 0000000000..9d3c7655a5 --- /dev/null +++ b/files/zh-cn/web/api/cssstylerule/index.html @@ -0,0 +1,54 @@ +--- +title: CSSStyleRule +slug: Web/API/CSSStyleRule +tags: + - API + - CSSOM + - 参考 + - 接口 +translation_of: Web/API/CSSStyleRule +--- +
{{ APIRef("CSSOM") }}
+ +

CSSStyleRule 表示一条 CSS 样式规则。它实现了 {{domxref("CSSRule")}} 接口,类型的值为 1CSSRule.STYLE_RULE)。

+ +

属性

+ +
+
{{domxref("CSSStyleRule.selectorText")}}
+
返回这条规则的、文本格式的选择器,例如 "h1,h2"
+
{{domxref("CSSStyleRule.style")}} {{readonlyinline}}
+
返回这条规则的 {{domxref("CSSStyleDeclaration")}} 对象。
+
{{domxref("CSSStyleRule.styleMap")}} {{readonlyinline}}
+
返回一个 {{domxref('StylePropertyMap')}} 对象,which provides access to the rule's property-value pairs.
+
+ +

规范

+ + + + + + + + + + + + + + + + + + + + + +
规范状态备注
{{ SpecName('CSSOM', '#the-cssstylerule-interface', 'CSSStyleRule') }}{{ Spec2('CSSOM') }}No changes
{{ SpecName('DOM2 Style', 'css.html#CSS-CSSStyleRule', 'CSSRule') }}{{ Spec2('DOM2 Style') }}
+ +

浏览器兼容性

+ + + +

{{Compat("api.CSSStyleRule")}}

diff --git a/files/zh-cn/web/api/cssstylerule/selectortext/index.html b/files/zh-cn/web/api/cssstylerule/selectortext/index.html new file mode 100644 index 0000000000..76a9007cd3 --- /dev/null +++ b/files/zh-cn/web/api/cssstylerule/selectortext/index.html @@ -0,0 +1,33 @@ +--- +title: CSSStyleRule.selectorText +slug: Web/API/CSSStyleRule/selectorText +translation_of: Web/API/CSSStyleRule/selectorText +--- +
{{APIRef("CSSOM") }}
+ +

概述

+ +

CSSRule.selectorText 属性返回CSS规则的选择符文本,只读。动态设置CSS规则,请看 Using dynamic styling information.

+ +

语法

+ +
string = cssRule.selectorText
+
+ +

例子

+ +
// for cssrule: body { background-color: darkblue; }
+var stylesheet = document.styleSheets[0];
+
+alert(stylesheet.cssRules[0].selectorText); // body
+
+ +

说明

+ +

浏览器解析选择符的时候可能会剔除不必要的空白字符

+ +

标准

+ + diff --git a/files/zh-cn/web/api/cssstylerule/style/index.html b/files/zh-cn/web/api/cssstylerule/style/index.html new file mode 100644 index 0000000000..def2974719 --- /dev/null +++ b/files/zh-cn/web/api/cssstylerule/style/index.html @@ -0,0 +1,43 @@ +--- +title: style +slug: Web/API/CSSStyleRule/style +translation_of: Web/API/CSSStyleRule/style +--- +

{{ ApiRef() }}

+ +

概述

+ +

返回 一个 {{ domxref("CSSStyleDeclaration") }}接口对象,它代表了{{ DOMXref("CSSRule") }}的 declaration block

+ +

语法

+ +
styleObj = cssRule.style
+
+ +

例子

+ +
function stilo() {
+  alert(document.styleSheets[0].cssRules[0].style.cssText);
+}
+// 弹出 "background-color: gray;"
+
+ +

备注

+ +

declaration block是样式规则中花括号内的部分(选择器就在花括号的外部)

+ +

相关链接

+ + + +

规范

+ +

DOM Level 2 CSS: style

+ +

{{ languages( {"en": "en/DOM/CSSStyleRule/style" } ) }}

+ +

浏览器兼容性

+ +

{{Compat("api.CSSStyleRule.style")}}

-- cgit v1.2.3-54-g00ecf