作者:AlbertYang,軟體設計師,Java工程師,前端工程師,愛閱讀,愛思考,愛編程,愛自由,信奉終生學習,每天學習一點點,就是領先的開始,
微信公眾號:AlbertYang
今天教大家使用CSS實作一個霓虹燈按鈕影片效果,大家有什么不懂的可以留言問我,視頻已經同步到B站,歡迎關注我的B站賬號,

視頻
視頻鏈接:https://www.bilibili.com/video/BV1Zi4y1F7ut
CSS霓虹燈按鈕影片,CSS實作炫酷的霓虹燈按鈕影片
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>霓虹燈按鈕:微信公眾號AlbertYang</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<!-- 容器 -->
<div class="container">
<!-- 按鈕 -->
<a href="#" style="--x:0"><span>關注</span></a>
<a href="#" style="--x:1"><span>收藏</span></a>
<a href="#" style="--x:2"><span>投幣</span></a>
<a href="#" style="--x:3"><span>點贊</span></a>
<a href="#" style="--x:4"><span>評論</span></a>
<a href="#" style="--x:5"><span>轉發</span></a>
</div>
</body>
</html>
CSS
/* 清除瀏覽器默認邊距,
使邊框和內邊距的值包含在元素的height和width內 */
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
/* flex布局,讓內容垂直和水平居中 */
body {
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
background: #000;
}
/* flex布局,讓內容垂直和水平居中,超過的部分換行顯示 */
.container {
display: flex;
justify-content: center;
align-items: center;
flex-wrap: wrap;
}
/* 按鈕的基本樣式 */
.container a {
position: relative;
padding: 15px 30px;
margin: 50px;
border: 2px solid #0f0;
font-size: 18px;
font-weight: 600;
text-decoration: none;
letter-spacing: 5px;
color: #fff;
filter: hue-rotate(calc(var(--x) * 60deg));
transition: 0.5s;
}
/* 滑鼠經過時改變按鈕樣式 */
.container a:hover {
transition-delay: 1.5s;
color: #000;
box-shadow: 0 0 10px #0f0,
0 0 20px #0f0,
0 0 40px #0f0,
0 0 80px #0f0,
0 0 160px #0f0,
0 0 320px #0f0;
}
a span {
position: relative;
z-index: 10;
}
/* 通過偽元素::before實作按鈕左邊的線 */
.container a::before {
content: "";
position: absolute;
left: -20px;
top: 50%;
transform: translateY(-50%);
background: #0f0;
width: 20px;
height: 2px;
box-shadow: 5px -8px 0 #0f0,
5px 8px 0 #0f0;
transition: width 0.5s, height 0.5s, left 0.5s,
box-shadow 0.5s;
transition-delay: 0s, 1s, 0s, 0.5s;
}
/* 滑鼠經過時改變線條的樣式 */
.container a:hover::before {
width: 60%;
height: 100%;
left: -2px;
box-shadow: 0 0 0 #0f0,
0 0 0 #0f0;
}
/* 通過偽元素::after實作按鈕右邊的線 */
.container a::after {
content: "";
position: absolute;
right: -20px;
top: 50%;
transform: translateY(-50%);
background: #0f0;
width: 20px;
height: 2px;
box-shadow: -5px -8px 0 #0f0,
-5px 8px 0 #0f0;
transition: width 0.5s, height 0.5s, right 0.5s,
box-shadow 0.5s;
transition-delay: 0s, 1s, 0s, 0.5s;
}
/* 滑鼠經過時改變線條的樣式 */
.container a:hover::after {
width: 60%;
height: 100%;
right: -2px;
box-shadow: 0 0 0 #0f0,
0 0 0 #0f0;
}

今天的學習就到這里了,由于本人能力和知識有限,如果有寫的不對的地方,還請各位大佬批評指正,有什么不明白的地方歡迎給我留言,如果想繼續學習提高,歡迎關注我,每天進步一點點,就是領先的開始,加油,如果覺得本文對你有幫助的話,歡迎轉發,評論,點贊!!!
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/246869.html
標籤:其他
