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-width/index.html | 175 ++++++++++++++++++++++++++++ 1 file changed, 175 insertions(+) create mode 100644 files/zh-cn/web/css/border-width/index.html (limited to 'files/zh-cn/web/css/border-width') diff --git a/files/zh-cn/web/css/border-width/index.html b/files/zh-cn/web/css/border-width/index.html new file mode 100644 index 0000000000..43ff5baa94 --- /dev/null +++ b/files/zh-cn/web/css/border-width/index.html @@ -0,0 +1,175 @@ +--- +title: border-width +slug: Web/CSS/border-width +translation_of: Web/CSS/border-width +--- +
{{CSSRef}}
+ +

概要

+ +

 border-width 属性可以设置盒子模型的边框宽度。

+ +

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

+ + + +

它是{{cssxref("border-top-width")}}, {{cssxref("border-right-width")}}, {{cssxref("border-bottom-width")}}, 和 {{cssxref("border-left-width")}}的简写;

+ +

语法

+ +
/* 用法一:明确指定宽度值 */
+/* 当给定一个宽度时,该宽度作用于选定元素的所有边框 */
+border-width: 5px;
+/* 当给定两个宽度时,该宽度分别依次作用于选定元素的横边与纵边 */
+border-width: 2px 1.5em;
+/* 当给定三个宽度时,该宽度分别依次作用于选定元素的上横边、纵边、下横边 */
+border-width: 1px 2em 1.5cm;
+/* 当给定四个宽度时,该宽度分别依次作用于选定元素的上横边、右纵边、下横边、左纵边 (即按顺时针依次作用) */
+border-width: 1px 2em 0 4rem;
+
+/* 用法二:使用全局关键字 */
+/* 可以使用的全局关键字有:inherit(继承),initial(初始值),unset(不设置) */
+border-width: inherit;
+
+/* 用法三:使用作用于 border-width 的关键字 */
+border-width: thin;
+border-width: medium;
+border-width: thick;
+
+
+ +

正式语法

+ +
{{csssyntax}}
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + +
关键字实例说明
thin +
+
+
细边线
medium +
+
+
中等边线
thick +
+
+
宽边线
+
+
+
+ +
+

提示:规范并没有规定关键字的实际值故在不同浏览器效果是不一样的,但显然thin≤medium≤thick,并且值在单个文档中是恒定的

+
+ +

示例

+ +

A mix of values and lengths

+ +

HTML

+ +
<p id="sval">
+    one value: 6px wide border on all 4 sides</p>
+<p id="bival">
+    two different values: 2px wide top and bottom border, 10px wide right and left border</p>
+<p id="treval">
+    three different values: 0.3em top, 9px bottom, and zero width right and left</p>
+<p id="fourval">
+    four different values: "thin" top, "medium" right, "thick" bottom, and 1em right</p>
+ +

CSS

+ +
#sval {
+    border: ridge #ccc;
+    border-width: 6px;
+}
+#bival {
+    border: solid red;
+    border-width: 2px 10px;
+}
+#treval {
+    border: dotted orange;
+    border-width: 0.3em 0 9px;
+}
+#fourval {
+    border: solid lightgreen;
+    border-width: thin medium thick 1em;
+}
+p {
+    width: auto;
+    margin: 0.25em;
+    padding: 0.25em;
+}
+ +

运行结果

+ +

{{ EmbedLiveSample('A_mix_of_values_and_lengths', 300, 180) }}

+ +

Specifications

+ + + + + + + + + + + + + + + + + + + + + + + + + + +
SpecificationStatusComment
{{SpecName('CSS3 Backgrounds', '#the-border-width', 'border-width')}}{{Spec2('CSS3 Backgrounds')}}No direct change, the {{cssxref("<length>")}} CSS data type extension has an effect on this property.
{{SpecName('CSS2.1', 'box.html#border-width-properties', 'border-width')}}{{Spec2('CSS2.1')}}Added the constraint that values' meaning must be constant inside a document.
{{SpecName('CSS1', '#border-width', 'border-width')}}{{Spec2('CSS1')}}Initial definition
+ +

浏览器兼容性

+ + + +

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

+ +

参考

+ + -- cgit v1.2.3-54-g00ecf