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/border/index.html | 134 ++++++++++++++++++++++++++++++++++ 1 file changed, 134 insertions(+) create mode 100644 files/zh-cn/web/css/border/index.html (limited to 'files/zh-cn/web/css/border/index.html') diff --git a/files/zh-cn/web/css/border/index.html b/files/zh-cn/web/css/border/index.html new file mode 100644 index 0000000000..4dd16768c2 --- /dev/null +++ b/files/zh-cn/web/css/border/index.html @@ -0,0 +1,134 @@ +--- +title: border +slug: Web/CSS/border +tags: + - CSS_参考 +translation_of: Web/CSS/border +--- +

{{ CSSRef() }}

+ +

概览

+ + + +

CSS的border属性是一个用于设置各种单独的边界属性的简写属性border可以用于设置一个或多个以下属性的值: {{Cssxref("border-width")}}, {{Cssxref("border-style")}}, {{Cssxref("border-color")}}。

+ + + +

{{EmbedInteractiveExample("pages/css/border.html")}}

+ +

和所有的简写属性一样,如果有缺省值会被设置成对应属性的初始值。同时需要注意设置border对{{cssxref("border-image")}}属性的影响,虽然border属性不能设置这个属性,但会把该属性重置为初始值none。这使得我们可以用border属性去重置整个样式表中的border设置。因为W3C计划在未来的标准中保留该属性,因此建议使用该属性重置边框设定。

+ +
+

注意: 虽然{{Cssxref("border-width")}},、{{Cssxref("border-style")}}和 {{Cssxref("border-color")}} 简写属性接受最多4个参数来为不同的边设置宽度、风格和颜色,但boder属性只接受三个参数,分别是宽度、风格和颜色,所以这样会使得四条边的边框相同。

+
+ +

Borders vs. outlines

+ +

边界border和轮廓outline很相似。然而轮廓在以下方面与边界不同

+ + + +

语法

+ +
/* style */
+border: solid;
+
+/* width | style */
+border: 2px dotted;
+
+/* style | color */
+border: outset #f33;
+
+/* width | style | color */
+border: medium dashed green;
+
+/* Global values */
+border: inherit;
+border: initial;
+border: unset;
+ +

可以使用下面列出的一个,两个或三个值来指定border属性。 值的顺序无关紧要。

+ +
+

注意:如果边框的样式未定义,它将不可见。 这是因为样式默认为none。

+
+ +

取值

+ +
+
border-width
+
请看 {{ Cssxref("border-width") }}.
+
border-style 
+
请看 {{ Cssxref("border-style") }}.
+
border-color 
+
{{cssxref("<color>")}} 可以确定border的颜色。如果这个值没有设置,它的默认值是元素的{{cssxref("color")}}属性值(是文字颜色而非背景色)。 请看{{ Cssxref("border-color") }}.
+
+

正式语法

+ +
{{csssyntax}}
+
+
+ +

示例

+ +

HTML

+ +
<div>I have a border, an outline, AND a box shadow! Amazing, isn't it?</div>
+ +

CSS

+ +
div {
+  border: 0.5rem outset pink;
+  outline: 0.5rem solid khaki;
+  box-shadow: 0 0 0 2rem skyblue;
+  border-radius: 12px;
+  font: bold 1rem sans-serif;
+  margin: 2rem;
+  padding: 1rem;
+  outline-offset: 0.5rem;
+}
+ +

结果

+ +

{{EmbedLiveSample('Example')}}

+ +

规范

+ + + + + + + + + + + + + + + + + + + + + + + + + + +
规范状态说明
{{SpecName('CSS3 Backgrounds', '#the-border-shorthands', 'border')}}{{Spec2('CSS3 Backgrounds')}}在理论上删除了对transparent的支持,因为{{cssxref("<color>")}}已经接受它作为一种有效的颜色值。这不会对实际使用有任何影响。
+ 虽然border不能给{{cssxref("border-image")}}赋特定的值,但可以用于重置{{cssxref("border-image")}}为初始值(none).
{{SpecName('CSS2.1', 'box.html#border-shorthand-properties', 'border')}}{{Spec2('CSS2.1')}} +

加入inherit关键字。
+ 接受transparent作为有效的颜色值。

+
{{SpecName('CSS1', '#border', 'border')}}{{Spec2('CSS1')}}初始定义
+ +

浏览器兼容性

+ +

{{Compat("css.properties.border")}}

-- cgit v1.2.3-54-g00ecf