CSS3 border-image 边框图片

183 阅读1分钟
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    .box {
      width: 300px;
      height: 300px;
      margin: 100px auto;
      background-color: pink;

      /* 边框图片属性 */
      
      /* 新版Chorm border-image 无效,需要加上 border 才能看到效果 */
      border: 1px solid;

      /* 边框图片的路径 */ 
      border-image-source: url(temp.png);

      /* 图片边框的裁剪 值为number类型所以不需要带px 4个值一样的时候可以写成简写 */
      /* border-image-slice: 30 30 30 30; */
      border-image-slice: 30;

      /* 图片边框的宽度 */
      border-image-width: 30px;  

      /* 边框图片的平铺 */
      /* repeat: 正常平铺 但是可能会显示不完整*/
      /* round: 平铺 但是保证图片完整显示*/
      /* stretch: 拉伸显示*/
      border-image-repeat: round;
    }
  </style>
</head>
<body>
  <div class="box">

  </div>
</body>
</html> 

  • demo效果

    不带 border-image-repeat 属性

    border-image-repeat: round;

  • 素材图片

    素材图片