网站首页 > 知识剖析 正文
对于前端开发人员来说,css是我们再熟悉不过的朋友的,它就相当于是我们页面的衣服,页面好不好看,就看我们css运用的是否炉火纯青。css学起来简单,但是我们要把它“修炼”到出神入化境界,那这可不是一丁点时间就可以的,需要我们的日积月累,时刻专研。
而今天,就带给大家一个CSS特效-霓虹灯按钮,这也是我看到很不错的效果,带来分享给大家,希望大家喜欢
效果如下:
那好,废话不多说,开始我们的CSS代码。
准备一个HTML标签
// 这里我们用div标签来模拟button按钮,标签可以随意,a、p、span等都可以
// 通常在开发中使用别的标签来代替button标签,是因为原始的标签样式不好看,
// 我们还得重置样式,而其他标签不带有样式,我们可以更好的控制自己想要的样式,
// 当然,button标签也是可以的,但是如前面所说,原始的样式需要我们重置。
<div class="btn">button</div>
CSS部分的代码
body {
margin: 0;
padding: 0;
background: #000; // 黑色背景,只为更能突出样式效果
}
// 初始化按钮样式
.btn {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
width: 200px;
height: 60px;
text-align: center;
line-height: 60px;
color: #fff;
font-size: 24px;
font-family: sans-serif;
text-decoration: none;
text-transform: uppercase;
box-sizing: border-box;
// linear-gradient() 渐变属性,函数用于创建一个表示两种或多种颜色线性渐变的图片
background: linear-gradient(90deg, #03a9f4, #f441a5, #ffeb3b, #03a9f4);
background-size: 400%;
border-radius: 30px;
}
初始样式为这样:
然后我们给按钮加上动画,代码如下:
.btn:hover {
// linear: 动画从开始到结束具有相同的速度。
// infinite: 无限次播放
animation: animate 8s linear infinite;
}
@keyframes animate {
0% {
background-position: 0%;
}
100% {
background-position: 400%;
}
}
效果就变为下面这样:
最后我们给它加上鼠标移上去的效果,代码如下:
.btn::before {
content: '';
position: absolute;
top: -5px;
left: -5px;
right: -5px;
bottom: -5px;
z-index: -1;
background: linear-gradient(90deg, #03a9f4, #f441a5, #ffeb3b, #03a9f4);
background-size: 400%;
border-radius: 40px;
opacity: 0;
transition: .5s;
}
.btn:hover::before {
filter: blur(20px);
opacity: 1;
animation: animate 8s linear infinite;
}
现在这样,就是我们的最终效果了:
就此,我们的霓虹灯的按钮效果就完成了
不足百行,我们就完成了这个效果,以下是我们的CSS的全部代码:
body {
margin: 0;
padding: 0;
background: #000;
}
.btn {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
width: 200px;
height: 60px;
text-align: center;
line-height: 60px;
color: #fff;
font-size: 24px;
font-family: sans-serif;
text-decoration: none;
text-transform: uppercase;
box-sizing: border-box;
background: linear-gradient(90deg, #03a9f4, #f441a5, #ffeb3b, #03a9f4);
background-size: 400%;
border-radius: 30px;
}
.btn:hover {
animation: animate 8s linear infinite;
}
@keyframes animate {
0% {
background-position: 0%;
}
100% {
background-position: 400%;
}
}
.btn::before {
content: '';
position: absolute;
top: -5px;
left: -5px;
right: -5px;
bottom: -5px;
z-index: -1;
background: linear-gradient(90deg, #03a9f4, #f441a5, #ffeb3b, #03a9f4);
background-size: 400%;
border-radius: 40px;
opacity: 0;
transition: .5s;
}
.btn:hover::before {
filter: blur(20px);
opacity: 1;
animation: animate 8s linear infinite;
}
- 上一篇: 10个冷门但非常实用前端开发者很少用的CSS规则
- 下一篇:已经是最后一篇了
猜你喜欢
- 2025-07-09 10个冷门但非常实用前端开发者很少用的CSS规则
- 2025-07-09 大厂都在用的10个css高级技巧,我敢说你最多用过3个!不服来辩!
- 2025-07-09 2025年Top30 CSS面试题及答案(css笔试题)
- 07-09带你看好玩的CSS-霓虹灯按钮(css霓虹灯效果的文字)
- 07-0910个冷门但非常实用前端开发者很少用的CSS规则
- 07-09大厂都在用的10个css高级技巧,我敢说你最多用过3个!不服来辩!
- 07-092025年Top30 CSS面试题及答案(css笔试题)
- 07-09ASP.NET Core Web API 接口限流(asp.net core web api教程)
- 07-09C# ASP.NET Core Web Api 与 MVC 模式下 body 参数传递,post 参数方式
- 07-09ASP.NET Core Web API 中的 JSON 修补程序
- 07-09Visual Studio Code安装C#开发工具包并编写ASP.NET Core Web应用
- 最近发表
-
- 带你看好玩的CSS-霓虹灯按钮(css霓虹灯效果的文字)
- 10个冷门但非常实用前端开发者很少用的CSS规则
- 大厂都在用的10个css高级技巧,我敢说你最多用过3个!不服来辩!
- 2025年Top30 CSS面试题及答案(css笔试题)
- ASP.NET Core Web API 接口限流(asp.net core web api教程)
- C# ASP.NET Core Web Api 与 MVC 模式下 body 参数传递,post 参数方式
- ASP.NET Core Web API 中的 JSON 修补程序
- Visual Studio Code安装C#开发工具包并编写ASP.NET Core Web应用
- 深入了解 ASP.NET Core 中的 IWebHostEnvironment 接口
- ASP.NET WebForms功能增强(三)(asp net web)
- 标签列表
-
- xml (46)
- css animation (57)
- array_slice (60)
- htmlspecialchars (54)
- position: absolute (54)
- datediff函数 (47)
- array_pop (49)
- jsmap (52)
- toggleclass (43)
- console.time (63)
- .sql (41)
- ahref (40)
- js json.parse (59)
- html复选框 (60)
- css 透明 (44)
- css 颜色 (47)
- php replace (41)
- css nth-child (48)
- min-height (40)
- xml schema (44)
- css 最后一个元素 (46)
- location.origin (44)
- table border (49)
- html tr (40)
- video controls (49)