css 边框流动效果

这篇博客展示了如何利用CSS的伪元素(::before和::after)结合动画来实现一个创新的边框效果。代码示例中,一个名为.txbox的div通过设置高度、边框、内边距等属性创建了基本框架,然后使用伪元素添加了一个旋转的白色背景和一个内部边框,通过keyframes定义动画实现3秒无限循环的旋转效果。
摘要由CSDN通过智能技术生成

通过伪元素及动画实现,复制即可食用
在这里插入图片描述

 <div class="txbox">border</div>
  .txbox {
          height: 200px;
          border: 1px solid #000;
          border-radius: 10px;
          position: relative;
          text-align: center;
          line-height: 200px;
          z-index: 1;
          overflow: hidden;
          background: #000;
        }
         .txbox::before {
          content: "";
          display: block;
          position: absolute;
          width: 60%;
          height: 60%;
          left: 50%;
          top: 50%;
          background: #fff;
          z-index: -2;
          transform-origin: 0 0;
          animation: rotate 3s infinite linear;
        }
          @keyframes rotate {
          to {
            transform: rotate(1turn);
          }
          // 0% {background: red;left: 0px;top: 0px;}
          // 25% {background: yellow;left: 200px;top: 0px; }
          // 50% {background: skyblue;left: 200px;top: 200px;}
          // 75% {background: green;left: 0px;top: 200px; }
          // 100% {background: #fff;left: 0px;top: 0px;}
        }
        .txbox::after {
          border-radius: 10px;
          content: "";
          display: block;
          position: absolute;
          border: 1px solid #000;
          width: calc( 100% - 4px);
          height: calc( 100% - 4px);
          left: 1px;
          top: 1px;
          background: #fff;
          z-index: -1;
        }
  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
你可以使用CSS3中的画属性和边框属性来实现边框线条流动画。以下是一个基本的示例代码: ``` <!DOCTYPE html> <html> <head> <title>CSS3 Border Animation</title> <style> .border-animation { width: 200px; height: 200px; border: 3px solid #000; animation: border-anim 2s infinite; } @keyframes border-anim { 0% { border-top: 3px solid #000; border-right: 3px solid #000; border-bottom: none; border-left: none; } 25% { border-top: none; border-right: 3px solid #000; border-bottom: 3px solid #000; border-left: none; } 50% { border-top: none; border-right: none; border-bottom: 3px solid #000; border-left: 3px solid #000; } 75% { border-top: 3px solid #000; border-right: none; border-bottom: none; border-left: 3px solid #000; } 100% { border-top: 3px solid #000; border-right: 3px solid #000; border-bottom: 3px solid #000; border-left: none; } } </style> </head> <body> <div class="border-animation"></div> </body> </html> ``` 在上面的代码中,我们定义了一个样式类`.border-animation`,并设置了其宽度、高度和3像素的黑色边框。接着,我们使用CSS3中的`animation`属性来定义画,指定了`border-anim`关键帧画和2秒的画持续时间,并设置`infinite`表示无限循环播放。 在关键帧画`border-anim`中,我们使用了五个关键帧来控制边框线条的变化。每个关键帧中,我们可以指定边框的样式和颜色,以及哪些边框线条需要显示或隐藏。 这个例子中,我们通过不同的组合方式来交替显示边框线条,从而实现了流动画的效果。你可以根据需要调整关键帧中的样式和时间间隔来实现不同的效果
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值