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>


相关推荐
m0_748235241 分钟前
前端实现获取后端返回的文件流并下载
前端·状态模式
m0_748240251 小时前
前端如何检测用户登录状态是否过期
前端
black^sugar1 小时前
纯前端实现更新检测
开发语言·前端·javascript
寻找沙漠的人2 小时前
前端知识补充—CSS
前端·css
GISer_Jing2 小时前
2025前端面试热门题目——计算机网络篇
前端·计算机网络·面试
m0_748245522 小时前
吉利前端、AI面试
前端·面试·职场和发展
理想不理想v2 小时前
webpack最基础的配置
前端·webpack·node.js
pubuzhixing2 小时前
开源白板新方案:Plait 同时支持 Angular 和 React 啦!
前端·开源·github
2401_857600952 小时前
SSM 与 Vue 共筑电脑测评系统:精准洞察电脑世界
前端·javascript·vue.js
2401_857600952 小时前
数字时代的医疗挂号变革:SSM+Vue 系统设计与实现之道
前端·javascript·vue.js