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>


相关推荐
木木黄木木26 分钟前
css炫酷的3D水波纹文字效果实现详解
前端·css·3d
美食制作家28 分钟前
【无标题】Threejs第一个3D场景
javascript·three
郁大锤1 小时前
Flask与 FastAPI 对比:哪个更适合你的 Web 开发?
前端·flask·fastapi
HelloRevit2 小时前
React DndKit 实现类似slack 类别、频道拖动调整位置功能
前端·javascript·react.js
ohMyGod_1232 小时前
用React实现一个秒杀倒计时组件
前端·javascript·react.js
eternal__day2 小时前
第三期:深入理解 Spring Web MVC [特殊字符](数据传参+ 特殊字符处理 + 编码问题解析)
java·前端·spring·java-ee·mvc
醋醋2 小时前
Vue2源码记录
前端·vue.js
艾克马斯奎普特2 小时前
Vue.js 3 渐进式实现之响应式系统——第四节:封装 track 和 trigger 函数
javascript·vue.js
江耳3 小时前
从10秒到无限流:我用Vercel+NextJS实现AI流式对话遇到的超时问题及解决方案
前端
总之就是非常可爱3 小时前
三分钟让你看懂alien-signals computed基本原理
前端