css:clip元素裁剪实现Loading加载效果边框
  ndh0xMjNGcR6 2023年12月08日 27 0

clip 属性定义了元素的哪一部分是可见的。clip 属性只适用于 position:absolute 的元素。

警告: 这个属性已被废弃。建议使用 clip-path

文档

(目录)

语法

/* 标准语法 */
clip: rect(<top>, <right>, <bottom>, <left>);

/* 向后兼容语法 */
clip: rect(<top> <right> <bottom> <left>);   

/* 默认值。不应用任何剪裁 */
clip: auto;

/* 从父元素继承 clip 属性的值 */
clip: inherit;
  • top 和 bottom 指定相对于盒子上边框边界 的偏移
  • right 和 left 指定了相对于盒子左边框边界 的偏移

截取各个边框

在这里插入图片描述 实现代码

<style>
  .box-wrap {
    display: flex;
    column-gap: 20px;
  }

  .box {
    position: relative;
    height: 200px;
    width: 200px;

    background-color: green;
    color: #fff;
    font-size: 24px;
    text-align: center;
    line-height: 200px;
  }

  .box::before {
    content: "";
    position: absolute;
    left: 0;
    top: 0;
    right: 0;
    bottom: 0;
    border: 2px solid #cd0000;
  }

  .box-top::before {
    /* 上边框 */
    clip: rect(0 200px 2px 0);
  }

  .box-bottom::before {
    /* 下边框 */
    clip: rect(198px, 200px, 200px, 0);
  }

  .box-left::before {
    /* 左边框 */
    clip: rect(0, 2px, 200px, 0);
  }

  .box-right::before {
    /* 右边框 */
    clip: rect(0, 200px, 200px, 198px);
  }
</style>

<div class="box-wrap">
  <div class="box">box</div>
  <div class="box box-top">box-top</div>
  <div class="box box-bottom">box-bottom</div>
  <div class="box box-left">box-left</div>
  <div class="box box-right">box-right</div>
</div>

实现Loading加载效果边框

在这里插入图片描述

实现代码

<style>
 .box {
    position: relative;
    height: 200px;
    width: 200px;

    background-color: green;
    color: #fff;
    font-size: 24px;
    text-align: center;
    line-height: 200px;
  }

  .box::before {
    content: "";
    position: absolute;
    left: 0;
    top: 0;
    right: 0;
    bottom: 0;
    border: 2px solid #cd0000;
    animation: borderAround 1.5s infinite linear;
  }

  @keyframes borderAround {
    0%,
    100% {
      clip: rect(0 200px 2px 0);
    }
    25% {
      clip: rect(0, 200px, 200px, 198px);
    }
    50% {
      clip: rect(198px, 200px, 200px, 0);
    }
    75% {
      clip: rect(0, 2px, 200px, 0);
    }
  }
</style>

<div class="box">box</div>

演示地址:https://mouday.github.io/front-end-demo/clip-path/loading.html

参考文章

  1. CSS实线边框loading动画实例页面

  2. CSS3/SVG clip-path路径剪裁遮罩属性简介

  3. 菜鸟教程 - CSS clip 属性

【版权声明】本文内容来自摩杜云社区用户原创、第三方投稿、转载,内容版权归原作者所有。本网站的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@moduyun.com

  1. 分享:
最后一次编辑于 2023年12月08日 0

暂无评论

推荐阅读
ndh0xMjNGcR6