With the CSS border-image
property, you can set an image to be used as the border around an element.
CSS border-image
属性允许您指定要使用的图像,而不是元素周围的正常边框。
该房产分为三部分:
用作边框的图像
在哪里切片图像
定义中间部分是否应重复或拉伸
我们将使用以下图像(称为“border.png”):
border-image
属性获取图像并将其切成九个部分, 就像井字棋盘一样。然后将角点放在角点处,然后将 中间部分按照您的指定重复或拉伸。
注意:要使 border-image
正常工作,该元素还需要 border
属性设置!
此处,重复图像的中间部分以创建边框:
An image as a border!
这是代码:
#borderimg
{
border: 10px solid transparent;
padding: 15px;
border-image: url(border.png)
30 round;
}
自己尝试一下 →
<!DOCTYPE html>
<html>
<head>
<style>
#borderimg {
border: 10px solid transparent;
padding: 15px;
border-image: url(border.png) 30 round;
}
</style>
</head>
<body>
<h1>The border-image Property</h1>
<p>Here, the middle sections of the image are repeated to create the border:</p>
<p id="borderimg">border-image: url(border.png) 30 round;</p>
<p>Here is the original image:</p><img src="border.png">
<p><strong>Note:</strong> Internet Explorer 10, and earlier versions, do not support the border-image property.</p>
</body>
</html>
在这里,图像的中间部分被拉伸以创建边框:
An image as a border!
这是代码:
#borderimg
{
border: 10px solid transparent;
padding: 15px;
border-image: url(border.png)
30 stretch;
}
自己尝试一下 →
<!DOCTYPE html>
<html>
<head>
<style>
#borderimg {
border: 10px solid transparent;
padding: 15px;
border-image: url(border.png) 30 stretch;
}
</style>
</head>
<body>
<h1>The border-image Property</h1>
<p>Here, the middle sections of the image are stretched to create the border:</p>
<p id="borderimg">border-image: url(border.png) 30 stretch;</p>
<p>Here is the original image:</p><img src="border.png">
<p><strong>Note:</strong> Internet Explorer 10, and earlier versions, do not support the border-image property.</p>
</body>
</html>
提示: border-image
属性实际上是以下属性的简写属性:
border-image-source
border-image-slice
border-image-width
border-image-outset
border-image-repeat
不同的切片值完全改变了边框的外观:
示例1:
border-image: url(border.png) 50 round;
示例2:
border-image: url(border.png) 20% round;
示例3:
border-image: url(border.png) 30% round;
这是代码:
#borderimg1 {
border: 10px solid transparent;
padding: 15px;
border-image: url(border.png)
50 round;
}
#borderimg2 {
border: 10px solid transparent;
padding: 15px;
border-image: url(border.png) 20% round;
}
#borderimg3 {
border: 10px solid transparent;
padding: 15px;
border-image: url(border.png)
30% round;
}
自己尝试一下 →
<!DOCTYPE html>
<html>
<head>
<style>
#borderimg1 {
border: 10px solid transparent;
padding: 15px;
border-image: url(border.png) 50 round;
}
#borderimg2 {
border: 10px solid transparent;
padding: 15px;
border-image: url(border.png) 20% round;
}
#borderimg3 {
border: 10px solid transparent;
padding: 15px;
border-image: url(border.png) 30% round;
}
</style>
</head>
<body>
<h1>The border-image Property</h1>
<p id="borderimg1">border-image: url(border.png) 50 round;</p>
<p id="borderimg2">border-image: url(border.png) 20% round;</p>
<p id="borderimg3">border-image: url(border.png) 30% round;</p>
<p><strong>Note:</strong> Internet Explorer 10, and earlier versions, do not support the border-image property.</p>
</body>
</html>
用于设置所有 border-image-* 属性的简写属性
指定要用作边框的图像的路径
指定如何切片边框图像
指定边框图像的宽度
指定边框图像区域延伸超出边框框的量
指定边框图像是否应该重复、圆角或拉伸