首页 > 其他分享 >有趣的 CSS - 好看的呼吸灯效果

有趣的 CSS - 好看的呼吸灯效果

时间:2023-03-25 21:03:10浏览次数:34  
标签:box 5px CSS rgba 有趣 border shadow 好看 255

整体效果

123.gif

这个效果主要用 css3 的 animation 属性来实现的。

这个效果可以用作在网站的整体 Loading,也可以放在网站首屏当一个 banner 的背景也是非常棒的!

代码部分

html 部分代码:

<div class="app">
  <span class="red"></span>
  <span class="green"></span>
  <span class="blue"></span>
</div>

写出三个圆,class 分别为 .red、.green、.blue。

css 部分代码:

.app{
  width:100%;
  height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
}
span{
  width: 60px;
  height: 60px;
  margin: 40px;
  border-radius: 50%;
}
.red{
  animation: just1 2s ease-in-out infinite alternate;
}
.green{
  animation: just2 3s ease-in-out infinite alternate;
}
.blue{
  animation: just3 4s ease-in-out infinite alternate;
}
@keyframes just1{
  0%{
    border: 5px solid rgba(255,0,0,0);
    box-shadow: 0 0 0 rgba(255,0,0,0),0 0 0 rgba(255,0,0,0) inset;
  }
  100%{
    border: 5px solid rgba(255,0,0,1);
    box-shadow: 0 0 70px rgba(255,0,0,0.7),0 0 15px rgba(255,0,0,0.5) inset;
  }
}
@keyframes just2{
  0%{
    border: 5px solid rgba(0,255,0,0);
    box-shadow: 0 0 0 rgba(0,255,0,0),0 0 0 rgba(0,255,0,0) inset;
  }
  100%{
    border: 5px solid rgba(0,255,0,1);
    box-shadow: 0 0 70px rgba(0,255,0,0.7),0 0 15px rgba(0,255,0,0.5) inset;
  }
}
@keyframes just3{
  0%{
    border: 5px solid rgba(0,0,255,0);
    box-shadow: 0 0 0 rgba(0,0,255,0),0 0 0 rgba(0,0,255,0) inset;
  }
  100%{
    border: 5px solid rgba(0,0,255,1);
    box-shadow: 0 0 70px rgba(0,0,255,0.7),0 0 15px rgba(0,0,255,0.5) inset;
  }
}

css 部分主要使用 animation 来实现边框及其阴影的大小变化,和其透明度的变化。

完整代码如下

html 页面:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="style.css">
    <title>好看的呼吸灯效果</title>
</head>
<body>
  <div class="app">
    <span class="red"></span>
    <span class="green"></span>
    <span class="blue"></span>
  </div>
</body>
</html>

css 样式:

/** style.css **/

*{
  margin:0;
  padding: 0;
}
body,html{
  background-color: #000;
}
.app{
  width:100%;
  height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
}
span{
  width: 60px;
  height: 60px;
  margin: 40px;
  border-radius: 50%;
}
.red{
  animation: just1 2s ease-in-out infinite alternate;
}
.green{
  animation: just2 3s ease-in-out infinite alternate;
}
.blue{
  animation: just3 4s ease-in-out infinite alternate;
}
@keyframes just1{
  0%{
    border: 5px solid rgba(255,0,0,0);
    box-shadow: 0 0 0 rgba(255,0,0,0),0 0 0 rgba(255,0,0,0) inset;
  }
  100%{
    border: 5px solid rgba(255,0,0,1);
    box-shadow: 0 0 70px rgba(255,0,0,0.7),0 0 15px rgba(255,0,0,0.5) inset;
  }
}
@keyframes just2{
  0%{
    border: 5px solid rgba(0,255,0,0);
    box-shadow: 0 0 0 rgba(0,255,0,0),0 0 0 rgba(0,255,0,0) inset;
  }
  100%{
    border: 5px solid rgba(0,255,0,1);
    box-shadow: 0 0 70px rgba(0,255,0,0.7),0 0 15px rgba(0,255,0,0.5) inset;
  }
}
@keyframes just3{
  0%{
    border: 5px solid rgba(0,0,255,0);
    box-shadow: 0 0 0 rgba(0,0,255,0),0 0 0 rgba(0,0,255,0) inset;
  }
  100%{
    border: 5px solid rgba(0,0,255,1);
    box-shadow: 0 0 70px rgba(0,0,255,0.7),0 0 15px rgba(0,0,255,0.5) inset;
  }
}

页面效果:

123.gif


以上就是所有代码,css3 有很多好玩的属性,可以实现非常多的效果,让页面视觉变的更丰富多彩!

这里是设计师工作日常,求点赞求关注!sky~


订阅号「设计师工作日常」, 求点赞求关注!!!

标签:box,5px,CSS,rgba,有趣,border,shadow,好看,255
From: https://blog.51cto.com/liujueyi/6149627

相关文章

  • css盒子水平垂直居中的几种方式
    第一种:son盒子中定位的上下左右全部为0,然后margin:auto1<!DOCTYPEhtml>2<htmllang="en">3<head>4<metacharset="UTF-8">5<metahttp-equiv="X-U......
  • 使用css绘制聊天气泡
    实现原理:给聊天区域的边框补充一个三角形1:左三角聊天气泡.left-box{max-width:540rpx;min-height:80rpx;border-radius:10rpx;border:2rpxsolid#D7......
  • css-输入框和按钮水平对齐
    <style> .container{ margin:0auto; margin-top:160px; width:600px; } .search{ width:100%; margin-top:20px; height:40px; } .searchin......
  • 若依框架----图标(可能不全)css
    把若依框架按钮的图标大概找出来了.el-icon-ice-cream-round:before{content:"\E6A0";}.el-icon-ice-cream-square:before{content:"\E6A3";}.el-icon-lollipop:......
  • CSS鼠标样式(cursor)总结(转载)
    CSS鼠标样式(cursor)总结 属性值示意图描述auto 默认值,由浏览器根据当前上下文确定要显示的光标样式default默认光标,不考虑上下文,通常是一个箭头none......
  • CSS选择器(包含CSS3新增的伪类和属性选择器等)
    选择器详见https://developer.mozilla.org/zh-CN/docs/Learn/CSS/Building_blocks/SelectorsCSS语法规则由两个主要的部分构成:选择器,以及一条或多条声明(样式)全局选择器......
  • vue中css变量的使用
    1、在css中使用变量(1)css中声明变量--color:red(2)使用变量color:var(--color)//color:red获取到全局声明变量值为red2、使用vue中的变量(1)在html标签中<span:style="{......
  • JAVAWEB-北京地铁查询系统(Servlet+JSP+CSS+SQL 实现)部分代码
    #这是我与伙伴合作完成的练习项目@小彭先森页面展示请见我的上一篇博客:https://www.cnblogs.com/rsy-bxf150/p/17253623.html完整代码请看我的GitHub:https://github.co......
  • JAVAWEB-北京地铁查询系统(Servlet+JSP+CSS+SQL 实现)
    Servlet+JSP+CSS+SQL实现完善的地铁系统页面#这是我和伙伴合作完成的练习项目#代码我将放在下一篇博客功能介绍:1.地铁线路查询:选择线路,输出线路上的站点名。2.地铁站......
  • CSS08.盒模型
    盒模型1.什么是标签的显示模式什么是标签的显示模式?标签以什么方式进行显示,比如div自己独占一行,比如span一行可以放多个作用:我们网页的标签非常多,在不同地方......