效果:

實作:
1. 添加標簽,可以看出一個 li 就是一個燈泡,可以多點,保證設定大小后整體能大過瀏覽器默認可視區寬度,
<ul class="container">
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
</ul>
2. 設定底層盒子 .container的基本樣式:
.container{
margin-top: 10px;
width: 100%;
height: 120px;
white-space: nowrap;
overflow: hidden;
}
white-space: nowrap; 子元素 li 不換行,會在在同一行上繼續排列,
overflow: hidden; 溢位隱藏,
3.設定 li 燈泡的樣式:
.container li{
display: inline-block;
margin-top: 30px;
margin-right: 50px;
width: 15px;
height: 30px;
border-radius: 50%;
position: relative;
}
display: inline-block; 換為行內塊元素,
border-radius: 50%; 角弧度,
4. 用雙偽類設定燈帽:
.container li::after{
content: '';
position: absolute;
top: -5px;
left: 50%;
transform: translateX(-50%);
width: 20px;
height: 12px;
background-color: rgb(27, 27, 27);
box-shadow: inset 0 0 3px rgb(129, 129, 129);
border-radius: 10px;
}
left: 50%;
transform: translateX(-50%); 水平居中
box-shadow: inset 0 0 3px rgb(129, 129, 129); 內陰影
5. 用雙偽類設定電線:
.container li::before{
content: '';
position: absolute;
top: -23px;
left: 15px;
width: 55px;
height: 30px;
border-bottom: 3px solid rgb(61, 61, 61);
border-radius: 50%;
}
border-bottom: 3px solid rgb(61, 61, 61);
border-radius: 50%; 這樣邊框可以呈現月牙形狀,
6. 設定 4 個影片效果,分別顯示不同的顏色閃爍:
@keyframes lan{
0%,100%{
background-color: rgba(4, 255, 242, 0.5);
}
50%{
background-color: rgb(4, 255, 242);
box-shadow: 0 0 10px rgb(4, 255, 242),
0 0 30px rgb(4, 255, 242),
0 0 50px rgb(4, 255, 242);
}
}
@keyframes huang{
0%,100%{
background-color: rgba(251, 255, 4,.5);
}
50%{
background-color: rgb(251, 255, 4);
box-shadow: 0 0 10px rgb(251, 255, 4),
0 0 12px rgb(251, 255, 4),
0 0 30px rgb(251, 255, 4);
}
}
@keyframes lv{
0%,100%{
background-color: rgba(33, 255, 4,.5);
}
50%{
background-color: rgb(33, 255, 4);
box-shadow: 0 0 10px rgb(33, 255, 4),
0 0 12px rgb(33, 255, 4),
0 0 30px rgb(33, 255, 4);
}
}
@keyframes zhi{
0%,100%{
background-color: rgba(255, 4, 255,.5);
}
50%{
background-color: rgb(255, 4, 255);
box-shadow: 0 0 10px rgb(255, 4, 255),
0 0 25px rgb(255, 4, 255),
0 0 40px rgb(255, 4, 255);
}
}
box-shadow: 陰影,添加了它就相當于發光,
7. 給不同位置的 li 添加影片屬性:
.container li:nth-of-type(2n+1){
animation: lan 2s infinite;
}.container li:nth-child(2n+2){
animation: huang 2.2s infinite;
}.container li:nth-child(3n+3){
animation: zhi 1.8s infinite;
}
.container li:nth-child(4n+4){
animation: lv 2.8s infinite;
}
完整代碼:
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
*{
margin: 0;
padding: 0;
box-sizing: border-box;
}
body{
background-color: rgb(0, 0, 0);
}
.container{
margin-top: 10px;
width: 100%;
height: 120px;
white-space: nowrap;
overflow: hidden;
}
.container li{
display: inline-block;
margin-top: 30px;
margin-right: 50px;
width: 15px;
height: 30px;
border-radius: 50%;
position: relative;
}
.container li::after{
content: '';
position: absolute;
top: -5px;
left: 50%;
transform: translateX(-50%);
width: 20px;
height: 12px;
background-color: rgb(27, 27, 27);
box-shadow: inset 0 0 3px rgb(129, 129, 129);
border-radius: 10px;
}
.container li::before{
content: '';
position: absolute;
top: -23px;
left: 15px;
width: 55px;
height: 30px;
border-bottom: 3px solid rgb(61, 61, 61);
border-radius: 50%;
}
.container li:nth-of-type(2n+1){
animation: lan 2s infinite;
}.container li:nth-child(2n+2){
animation: huang 2.2s infinite;
}.container li:nth-child(3n+3){
animation: zhi 1.8s infinite;
}
.container li:nth-child(4n+4){
animation: lv 2.8s infinite;
}
@keyframes lan{
0%,100%{
background-color: rgba(4, 255, 242, 0.5);
}
50%{
background-color: rgb(4, 255, 242);
box-shadow: 0 0 10px rgb(4, 255, 242),
0 0 30px rgb(4, 255, 242),
0 0 50px rgb(4, 255, 242);
}
}
@keyframes huang{
0%,100%{
background-color: rgba(251, 255, 4,.5);
}
50%{
background-color: rgb(251, 255, 4);
box-shadow: 0 0 10px rgb(251, 255, 4),
0 0 12px rgb(251, 255, 4),
0 0 30px rgb(251, 255, 4);
}
}
@keyframes lv{
0%,100%{
background-color: rgba(33, 255, 4,.5);
}
50%{
background-color: rgb(33, 255, 4);
box-shadow: 0 0 10px rgb(33, 255, 4),
0 0 12px rgb(33, 255, 4),
0 0 30px rgb(33, 255, 4);
}
}
@keyframes zhi{
0%,100%{
background-color: rgba(255, 4, 255,.5);
}
50%{
background-color: rgb(255, 4, 255);
box-shadow: 0 0 10px rgb(255, 4, 255),
0 0 25px rgb(255, 4, 255),
0 0 40px rgb(255, 4, 255);
}
}
</style>
</head>
<body>
<ul class="container">
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
</ul>
</body>
</html>
總結:
雖然實作不難,但效果還是挺好看的,
其它文章:
炫彩流光文字 html+css
氣泡浮動背景特效 html+css
簡約時鐘特效 html+css+js
賽博朋克風格按鈕 html+css
仿網易云官網輪播圖 html+css+js
水波加載影片 html+css
導航欄滾動漸變效果 html+css+js
書本翻頁 html+css
3D立體相冊 html+css
霓虹燈繪畫板效果 html+css+js
記一些css屬性總結(一)
Sass總結筆記
…等
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/267392.html
標籤:其他
