当前位置: 移动技术网 > IT编程>网页制作>CSS > 详解CSS3中border-image的使用

详解CSS3中border-image的使用

2019年07月25日  | 移动技术网IT编程  | 我要评论

变化 作文,北京电影院排片表,南京南动车所塌方

最近在项目中用到了border-image,一直是只知其名,不知其用。

最终效果是这样的:且随着border宽度变化。下图灰色部分带斜纹的是border
2015718174527412.png (600×449)

先看下css:

css code复制内容到剪贴板
  1. border-width40px;   
  2. border-stylesolid;   
  3. border-image-source: url('http://das.alipay.net/shulaibao/img/repeat_padding_bg_400px.png');   
  4. border-image-slice: 40;   
  5. border-image-repeatrepeat;   
  6. background#fff;   
  7. width800px;  

首先它必须是和border一起用,如果border为none,它也无效
实际是替换border-style,当border-image-source或border-image无效时,border-style就会有效了

和background一样,border-image也有简写的写法

简写的语法:

css code复制内容到剪贴板
  1. border-image:<'border-image-source'> || <'border-image-slice'> [ / <'border-image-width'> | / <'border-image-width'>? / <'border-image-outset'> ]? || <'border-image-repeat'>  

如上所示,包含了5个属性,详细分解如下:

图片地址: border-image-source,很好理解,要么有要么没有

css code复制内容到剪贴板
  1. border-image-source:url('') || none  

图片切片: border-image-slice,不太好理解,是实现效果的精华,它把border-image-source切割成9部分,俗称九宫格,4个角,4个边框,1个中间区域
2015718174620471.png (600×317)

语法: 

css code复制内容到剪贴板
  1. [<number> | <percentage>]{1,4} && fill?   

 

 border-image-slice: slice  /* one-value syntax   */  e.g. border-image-slice: 30%;
 border-image-slice: horizontal vertical    /* two-value syntax   */  e.g. border-image-slice: 10% 30%;
 border-image-slice: top vertical bottom    /* three-value syntax */  e.g. border-image-slice: 30 30% 45;
 border-image-slice: top right bottom left  /* four-value syntax  */  e.g. border-image-slice: 7 12 14 5;
 border-image-slice: … fill /* the fill value can be placed between any value */ e.g. border-image-slice: 10% fill 7 12;
 border-image-slice: inherit
 值只能是写数值,百分比(相对图片的宽度或高度),而长度(px,em等)是不允许的且无效

图片宽度: border-image-width 代替border width
图片外凸: border-image-outset
图片重复: border-image-repeat,背景是否重复,默认值为stretch(拉伸)

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网