指定作为div元素周围边框的图像:
#borderimg {
-webkit-border-image: url(border.png) 30 round; /* Safari 3.1-5 */
-o-border-image: url(border.png) 30 round; /* Opera 11-12.1 */
border-image: url(border.png) 30 round;
}
尝试一下
语法
border-image: source slice width outset repeat|initial|inherit;
实际渲染规则
通过裁切属性值,将边框背景图切出了“九宫格”的模型,那这张背景图怎么对应地贴在div的边框上呢?
<————————>

- 如图 在border-image中的橙红色的四个边角只会呆在border的四个角,并且水平和垂直方向均被拉伸来填充border的四个角。
- 如图 上下区域即border-top-image和border-bottom-image受到第一个参数——水平方向效果影响:如果为repeat,则此区域被水平重复(round水平平铺,stretch水平拉伸)来填充对应的上下border【该区域在垂直方向上首先会按所对应的border-image-width的值等比缩放,然后再按参数设置在边框水平方向上进行重复或平铺或拉伸】
- 左右区域border-left-image和border-right-image 的作用效果亦然【该区域在水平方向上首先会按所对应的border-image-width的值等比缩放,然后再按参数设置在边框垂直方向上进行重复或平铺或拉伸】

下图(27×3)px *(27×3)pxpng 做实验,我给不同部位加了一个序号做标志,便于观察。

// 加一个蓝色背景的父级,便于我们分析效果。
.border_image {
width: 400px;
height: 115px;
border: 3em double orange;
-webkit-border-image: url(border.png) 27 round;
border-image: url(border.png) 27 round;
}
.box {
background: blue;
}
<div class="box">
<div class="border_image"></div>
</div>
效果如下

//去掉重复属性,即默认都为stretch
border-image: url(border.png) 27;
效果如下

//使用repeat
border-image: url(border.png) 27 repeat;
效果如下

//边框宽度改变
border-image: url(border.png) 27 repeat stretch;
border-width: 3rem 1rem;
效果如下

|