class="w3-codespan">border-color
属性用于设置四个边框的颜色。
颜色可以通过以下方式设置:
name - 指定颜色名称,例如“red”
HEX - 指定一个十六进制值,例如“#ff0000”
RGB - 指定 RGB 值,例如“rgb(255,0,0)”
HSL - 指定 HSL 值,例如“hsl(0, 100%, 50%)”
透明的
注意:如果未设置class="w3-codespan">border-color
,则继承元素的颜色。
不同边框颜色的演示:
p.one
{
border-style: solid;
border-color: red;
}
p.two
{
border-style: solid;
border-color: green;
}
p.three {
border-style: dotted;
border-color:
blue;
}
结果 :
自己尝试一下 →
<!DOCTYPE html>
<html>
<head>
<style>
p.one {
border-style: solid;
border-color: red;
}
p.two {
border-style: solid;
border-color: green;
}
p.three {
border-style: dotted;
border-color: blue;
}
</style>
</head>
<body>
<h2>The border-color Property</h2>
<p>This property specifies the color of the four borders:</p>
<p class="one">A solid red border</p>
<p class="two">A solid green border</p>
<p class="three">A dotted blue border</p>
<p><b>Note:</b> The "border-color" property does not work if it is used alone. Use the "border-style" property to set the borders first.</p>
</body>
</html>
class="w3-codespan">border-color
属性可以有 1 到 4 个值(例如 上边框、右边框、下边框和左边框)。
p.one {
border-style: solid;
border-color: red green blue yellow;
/* red top, green right, blue bottom and yellow left */
}
自己尝试一下→
<!DOCTYPE html>
<html>
<head>
<style>
p.one {
border-style: solid;
border-color: red green blue yellow; /* red top, green right, blue bottom and yellow left */
}
</style>
</head>
<body>
<h2>The border-color Property</h2>
<p>The border-color property can have from one to four values (for the top border, right border, bottom border, and the left border):</p>
<p class="one">A solid multicolor border</p>
</body>
</html>
边框的颜色也可以使用十六进制值 (HEX) 指定:
p.one {
border-style: solid;
border-color: #ff0000; /* red
*/
}
自己尝试一下 →
<!DOCTYPE html>
<html>
<head>
<style>
p.one {
border-style: solid;
border-color: #ff0000; /* red */
}
p.two {
border-style: solid;
border-color: #0000ff; /* blue */
}
p.three {
border-style: solid;
border-color: #bbbbbb; /* grey */
}
</style>
</head>
<body>
<h2>The border-color Property</h2>
<p>The color of the border can also be specified using a hexadecimal value (HEX):</p>
<p class="one">A solid red border</p>
<p class="two">A solid blue border</p>
<p class="three">A solid grey border</p>
</body>
</html>
或者使用 RGB 值:
p.one {
border-style: solid;
border-color: rgb(255, 0, 0);
/* red */
}
自己尝试一下 →
<!DOCTYPE html>
<html>
<head>
<style>
p.one {
border-style: solid;
border-color: rgb(255, 0, 0); /* red */
}
p.two {
border-style: solid;
border-color: rgb(0, 0, 255); /* blue */
}
p.three {
border-style: solid;
border-color: rgb(187, 187, 187); /* grey */
}
</style>
</head>
<body>
<h2>The border-color Property</h2>
<p>The color of the border can also be specified using RGB values:</p>
<p class="one">A solid red border</p>
<p class="two">A solid blue border</p>
<p class="three">A solid grey border</p>
</body>
</html>
您还可以使用 HSL 值:
p.one {
border-style: solid;
border-color: hsl(0, 100%, 50%);
/* red */
}
自己尝试一下 →
<!DOCTYPE html>
<html>
<head>
<style>
p.one {
border-style: solid;
border-color: hsl(0, 100%, 50%); /* red */
}
p.two {
border-style: solid;
border-color: hsl(240, 100%, 50%); /* blue */
}
p.three {
border-style: solid;
border-color: hsl(0, 0%, 73%); /* grey */
}
</style>
</head>
<body>
<h2>The border-color Property</h2>
<p>The color of the border can also be specified using HSL values:</p>
<p class="one">A solid red border</p>
<p class="two">A solid blue border</p>
<p class="three">A solid grey border</p>
</body>
</html>
您可以在我们的 CSS 颜色章节中了解有关 HEX、RGB 和 HSL 值的更多信息。