首页 前端知识 用CSS3实现边框流动,让你的网页更有创意和个性

用CSS3实现边框流动,让你的网页更有创意和个性

2024-02-03 12:02:35 前端知识 前端哥 829 471 我要收藏

前言

边框流动动画是一种非常常见的效果,能够让网页看起来更加生动有趣。通过使用 CSS3,我们可以轻松地实现这种动画效果。本文将介绍如何使用 CSS3 实现边框流动效果,下面一起来看看吧。


实现效果

在这里插入图片描述


实现思路

  1. 首先我们先创建一个盒子容器;
  2. 设置字体样式,并将内容居中;
  3. 使用伪元素 before 创建一个渐变盒子;
  4. 使用伪元素 after 再创建一个盒子;
  5. 然后给渐变盒子设置旋转动画;
  6. 最后隐藏盒子以外的内容。

完整源码

<template>
  <div>
    <div class="boxes">
      <p>css</p>
    </div>
  </div>
</template>
<style scoped>
.boxes {
  position: relative;
  width: 200px;
  height: 200px;
  background: rgba(0, 0, 0, 0.8);
  border-radius: 16px;
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: hidden;
}
.boxes p {
  color: #fff;
  font-size: 24px;
  z-index: 1;
}
.boxes::before {
  content: "";
  position: absolute;
  width: 100px;
  height: 140%;
  background: linear-gradient(rgb(24, 98, 235), rgb(229, 66, 6));
}
.boxes::after {
  content: "";
  position: absolute;
  background: #0e1532;
  inset: 4px; /* inset 是 top、bottom、left、right 都为5px的简写*/
  border-radius: 16px;
}
.boxes::before {
  animation: rotate 4s linear infinite;
}
@keyframes rotate {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}
</style>

或者,你还可以这样:

在这里插入图片描述

完整源码

<template>
  <div class="card">
    <div class="bg"></div>
    <div class="blob"></div>
  </div>

</template>
<style scoped>
.card {
  position: relative;
  width: 200px;
  height: 250px;
  border-radius: 14px;
  z-index: 1111;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  box-shadow: 20px 20px 60px #bebebe, -20px -20px 60px #ffffff;
}

.bg {
  position: absolute;
  top: 5px;
  left: 5px;
  width: 190px;
  height: 240px;
  z-index: 2;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(24px);
  border-radius: 10px;
  overflow: hidden;
  outline: 2px solid white;
}

.blob {
  position: absolute;
  z-index: 1;
  top: 50%;
  left: 50%;
  width: 150px;
  height: 150px;
  border-radius: 50%;
  background-color: #ff0000;
  opacity: 1;
  filter: blur(12px);
  animation: blob-bounce 5s infinite ease;
}

@keyframes blob-bounce {
  0% {
    transform: translate(-100%, -100%) translate3d(0, 0, 0);
  }

  25% {
    transform: translate(-100%, -100%) translate3d(100%, 0, 0);
  }

  50% {
    transform: translate(-100%, -100%) translate3d(100%, 100%, 0);
  }

  75% {
    transform: translate(-100%, -100%) translate3d(0, 100%, 0);
  }

  100% {
    transform: translate(-100%, -100%) translate3d(0, 0, 0);
  }
}
</style>
转载请注明出处或者链接地址:https://www.qianduange.cn//article/1153.html
标签
评论
发布的文章

jQuery ---- 插件

2024-02-15 14:02:06

CSS-JavaScript-Jquery-Servlet

2024-02-15 14:02:00

大家推荐的文章
会员中心 联系我 留言建议 回顶部
复制成功!