border-image 經過指定一張圖片來取替 border-style 定義的樣式,但 border-image 生效的前提是: border-style 和 border-width 同時爲有效值(即 border-style 不爲 none,border-width 不爲 0)。html
border-image: none | <image>
複製代碼
border-image的背景圖使用url()調用,圖片能夠是相對路徑或是絕對路徑,也能夠不使用圖片,即border-image:none;
none 表示border-image不作任何效果,邊框使用 border-style 指定的樣式。chrome
bordre-image-slice [<number> | <percentage>]{1,4} && fill?
複製代碼
border-image-slice 從名字上看就很好理解:邊框圖像切片。指定4個值(4條分割線:top, right, bottom, left)將 border-image-source 分割成9宮格,以下: segmentfault
border-image-slice 四條線的值類型爲:number | percentage瀏覽器
舉個簡單的例子,前面提到,支持百分比寬度,因此這裏「30% 35% 40% 30%」的示意能夠用下圖表示:bash
關鍵字:fill
做用是將border-image-source九宮格中間那一塊切片做爲DOM節點的背景。
素材圖片box.png: 測試
.box {
width: 27px;
height:27px;
border: 27px solid;
border-image: url(box.png) 27 27 27 27 fill repeat stretch;
}
複製代碼
border-image-width: [ <length> | <percentage> | <number> | auto ]{1,4}
複製代碼
border-image-width 字面意思是邊框圖片寬度,做用是將 DOM 節點分割成九宮格。
假設 border-image-slice 分割 border-image-source 的九宮格爲A, border-image-width 分割 DOM 的九宮格爲 B,A 與 B 的每一個格子存在一一對應關係,具體以下: url
border-image-width 參數的四種類型:spa
注:3d
border-image-repeat: [ stretch | repeat | round | space ]{1,2}
複製代碼
border-image-repeat 字面意義是 邊框圖片平鋪。做用是指定 border-image 的平鋪方式。語法上最多可接收兩個參數,第一個參數指定水平方向邊框的平鋪方式,第二個參數指定垂直方向邊框的平鋪方式,九宮格的中間區域受這兩參數的共同影響,以下: code
border-image-outset: [ <length> | <number> ]{1,4}
複製代碼
border-image-outset做用是把原來的貼圖位置向外延伸
.box {
margin: 0 auto;
width: 81px;
height: 81px;
border: 27px solid rgba(0,0,0,.1);
border-image-source: url(//misc.aotu.io/leeenx/border-image/box.png);
border-image-slice: 27 27 27 27;
border-image-repeat: repeat;
}
.outset {
border-image-outset: 27px;
}
複製代碼
用於繪畫 border image 的區域叫 border image area,它默認與邊框盒子(border box)徹底重合。簡單地說,border image area 就是 border-image-width 分割出來的九宮格。
上面有提到,border image area 默認與 border-box 是重合關係。
若是把標準後退到發展階段,在發展階段,DOM節點由 border-width 分割爲九宮格,這個時期的 border-box 就是 border image area。
到了成熟階段(即本章介紹的版本),border-box 與 border image area 是默認重合的兩個空間,border-box 只負責盒子模型上的事務,border image area 則專一於邊框圖像空間分割。
在實際使用過程當中,發現 border-width 也能夠分割 border image area。以下:
.box {
margin: 0 auto;
width: 27px;
height: 27px;
border: 27px solid rgba(242,181,78,.3);
border-image-source: url(http://7xv39r.com1.z0.glb.clouddn.com/box.png);
border-image-slice: 27 27 27 27 fill;
border-image-repeat: stretch stretch;
}
複製代碼
.box {
margin: 0 auto;
width: 27px;
height: 27px;
border: 27px solid rgba(242,181,78,.3);
border-image-source: url(http://7xv39r.com1.z0.glb.clouddn.com/box.png);
border-image-slice: 27 27 27 27 fill;
border-image-outset: 10px;
border-image-repeat: stretch stretch;
}
複製代碼
border-image:
<‘border-image-source’> ||
<‘border-image-slice’> [ / <‘border-image-width’> | / <‘border-image-width’>? / <‘border-image-outset’> ]? ||
<‘border-image-repeat’>
複製代碼
因爲 border-image-slice、border-image-width 與 border-image-outset 這三者的參數類似,因此有必要說一下,這三個參數在簡寫裏有兩個注意點:
border-image: url(http://7xv39r.com1.z0.glb.clouddn.com/box.png) 27 27 27 27 / / 10px;
複製代碼
border-image: url(http://7xv39r.com1.z0.glb.clouddn.com/box.png) 27 27 27 27 / 10px / 10px;
複製代碼