border-image 边框图片
1. 官方解释
CSS 属性允许在元素的边框上绘制图像。这使得绘制复杂的外观组件更加简单,也不用在某些情况下使用九宫格了。使用 border-image
时,其将会替换掉 border-style
属性所设置的边框样式。虽然规范要求使用 border-image
时边框样式必须存在,但一些浏览器可能没有实现这一点。
2. 解释
3. 语法
border-image:source slice repeat;
包含属性
4. 实例
.demo{
width: px;
height: px;
background: #ccc;
border-width: px;
border-style: solid;
border-image: url(./../img/border-image.jpg);
}
效果图
- 使用
border-image-source
为元素设定一个边框。
.demo2{
width: px;
height: px;
background: #ccc;
border-width: px;
border-style: solid;
border-image-source: url(./../img/border-image.jpg);
}
效果图
- 我们在 demo2 上增加
border-image-slice
。
.demo2{
width: px;
height: px;
background: #ccc;
border-width: px;
border-style: solid;
border-image-source: url(./../img/border-image.jpg);
border-image-slice: ;
}
效果图
.demo2{
width: px;
height: px;
background: #ccc;
border-width: px;
border-style: solid;
border-image-source: url(./../img/border-image.jpg);
border-image-slice:;
border-image-outset:px;
}
效果图
- 使用
border-image-repeat
来为 demo2 设定图片的填充形式
.demo2{
width: px;
height: px;
background: #ccc;
border-width: px;
border-style: solid;
border-image-source: url(./../img/border-image.jpg);
border-image-slice:;
border-image-outset:px;
border-image-repeat: repeat;
}
效果图
5. 兼容性
IE | Edge | Firefox | Chrome | Safari | Opera | ios | android |
---|---|---|---|---|---|---|---|
11 | 12+ | 50+ | 5+ | 9.1+ | 43+ | 9.3+ | 2.1+ |
6. 经验分享
.demo{
border-width:px;
border-image-slice:;
}
还有一点要注意的是 slice
不需要挂单位。
2. 如果想填充中心可以加上-webkit-border-image
就像下面这样
.demo{
-webkit-border-image: url(./../img/border-image.jpg) stretch;
}