border-image(边框图片)
在css中可以使用border-image属性,使用图片来作为元素的边框,来创建边框图片。border-image是五个border-image-&属性的组合
1 2 3 4 5 6 7 8 9
| border-image-source:源文件
border-image-slice:定义边框图像从什么位置开始分割
border-image-width:: 定义边框的厚度
border-image-outset: 定义边框图像的外延尺寸
border-image-repeat:定义边框图像的平铺方式
|
1.border-image-source
指定一个图片来替换边框的默认样式,当为none时,边框显示默认样式
1 2 3 4 5 6 7
|
border-image-source:none
border-image-source: url(image.jpg); border-image-source: linear-gradient(to top, red, yellow);
|
2.border-image-slice
border-image-slice将引用划分多个区域,这些区域组成了一个元素边框

- 区域 1-4 为角区域(corner region)。每一个都被用于组成最终边框图像的四个角。
- 区域 5-8 边区域(edge region)。在最终的边框图像中重复、缩放或修改它们以匹配元素的大小。
- 区域 9 为中心区域(middle region)。它在默认情况下会被丢弃,但如果设置了关键字
fill
,则会将其用作元素的背景图像。
1 2 3 4 5 6 7 8 9 10 11 12 13
| border-image-slice: 30%;
border-image-slice: 10% 30%;
border-image-slice: 30 30% 45;
border-image-slice: 7 12 14 5;
border-image-slice: 10% fill 7 12;
|
案例
3.border-image-width.
定义边界图片的宽度
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| border-image-width: auto;
border-image-width: 1rem;
border-image-width: 25%;
border-image-width: 3;
border-image-width: 2em 3em;
border-image-width: 5% 15% 10%;
border-image-width: 5% 2em 10% auto;
|
4.border-image-outset
图像边框相对于边框边界向外偏移的距离
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| border-image-outset: 1rem;
border-image-outset: 1.5;
border-image-outset: 1 1.2;
border-image-outset: 30px 2 45px;
border-image-outset: 7px 12px 14px 5px;
|
5.border-image-repeat
如何填充使用 border-image-slice 属性分割的图像边框
1 2 3 4 5 6 7 8
| border-image-repeat: stretch; border-image-repeat: repeat;
border-image-repeat: space;
border-image-repeat: round stretch;
|