CSS3:border-image





html 复制代码
<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8">
</head>

<body>
  <p>原始图片</p>
  <img src="./images/border1.png" alt="">
  <p>一、</p>
  <p>border: 27px solid transparent;</p>
  <p>border-image-source: url(./images/border1.png);</p>
  <div class="border-image1"></div>

  <p>二、</p>
  <p>border: 27px solid transparent;</p>
  <p>border-image-source: url(./images/border1.png);</p>
  <p>border-image-slice: 27 27 27 27;</p>
  <p>border-image-repeat: stretch;(图像边界默认拉伸)</p>
  <div class="border-image2"></div>

  <p>三、</p>
  <p>border: 27px solid transparent;</p>
  <p>border-image-source: url(./images/border1.png);</p>
  <p>border-image-slice: 27;</p>
  <p>border-image-repeat: repeat;(图像边界重复)</p>
  <div class="border-image3"></div>

  <p>四、</p>
  <p>border: 27px solid transparent;</p>
  <p>border-image-source: url(./images/border1.png);</p>
  <p>border-image-slice: 27;</p>
  <p>border-image-repeat: round;(图像边界铺满)</p>
  <div class="border-image4"></div>

  <p>五、</p>
  <p>border: 10px solid transparent;</p>
  <p>border-image: url(./images/border1.png) 27 round;</p>
  <div class="border-image5"></div>
  <p>原始图片</p>
  <img src="./images/border2.png" alt="">

  <p>六、</p>
  <div>border: 64px solid transparent;</div>
  <div> border-image-source: url(./images/border2.png);</div>
  <div>border-image-slice: 64;</div>
  <div class="border-image6"></div>

  <p>七、相比于background-image,优势在于等比缩放时可以保证四个角的宽度不变</p>
  <div>border: 64px solid transparent;</div>
  <div> border-image-source: url(./images/border2.png);</div>
  <div>border-image-slice: 64 fill;(fill保留图像的中间部分)</div>
  <div class="border-image7"></div>
  <p>八、</p>
  <div>background-image: url(./images/border2.png);</div>
  <div>background-size: 100% 100%;</div>
  <div class="border-image8"></div>
</body>

</html>

<style>
  * {
    box-sizing: border-box;
  }

  .border-image1 {
    width: 300px;
    height: 150px;
    border: 27px solid transparent;
    border-image-source: url(./images/border1.png);
  }

  .border-image2 {
    width: 300px;
    height: 150px;
    border: 27px solid transparent;
    border-image-source: url(./images/border1.png);
    border-image-slice: 27 27 27 27;
  }

  .border-image3 {
    width: 300px;
    height: 150px;
    border: 27px solid transparent;
    border-image-source: url(./images/border1.png);
    border-image-slice: 27;
    border-image-repeat: repeat;
  }

  .border-image4 {
    width: 300px;
    height: 150px;
    border: 27px solid transparent;
    border-image-source: url(./images/border1.png);
    border-image-slice: 27;
    border-image-repeat: round;
  }

  .border-image5 {
    width: 300px;
    height: 150px;
    border: 10px solid transparent;
    border-image: url(./images/border1.png) 27 round;
  }

  .border-image6 {
    width: 468px;
    height: 232px;
    border: 64px solid transparent;
    border-image-source: url(./images/border2.png);
    border-image-slice: 64;
  }

  .border-image7 {
    width: 468px;
    height: 232px;
    border: 64px solid transparent;
    border-image-source: url(./images/border2.png);
    border-image-slice: 64 fill;
  }

  .border-image8 {
    width: 468px;
    height: 232px;
    background-image: url(./images/border2.png);
    background-size: 100% 100%;
  }
</style>


相关推荐
bysking18 分钟前
【前端-组件】定义行分组的表格表单实现-bysking
前端·react.js
王哲晓33 分钟前
第三十章 章节练习商品列表组件封装
前端·javascript·vue.js
fg_41137 分钟前
无网络安装ionic和运行
前端·npm
理想不理想v38 分钟前
‌Vue 3相比Vue 2的主要改进‌?
前端·javascript·vue.js·面试
酷酷的阿云1 小时前
不用ECharts!从0到1徒手撸一个Vue3柱状图
前端·javascript·vue.js
微信:137971205871 小时前
web端手机录音
前端
齐 飞1 小时前
MongoDB笔记01-概念与安装
前端·数据库·笔记·后端·mongodb
神仙别闹1 小时前
基于tensorflow和flask的本地图片库web图片搜索引擎
前端·flask·tensorflow
aPurpleBerry2 小时前
JS常用数组方法 reduce filter find forEach
javascript
GIS程序媛—椰子2 小时前
【Vue 全家桶】7、Vue UI组件库(更新中)
前端·vue.js