溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

CSS中icon圖標(biāo)之純CSS如何實(shí)現(xiàn)帶動(dòng)畫效果的天氣圖標(biāo)

發(fā)布時(shí)間:2021-08-26 15:05:02 來(lái)源:億速云 閱讀:137 作者:小新 欄目:web開(kāi)發(fā)

這篇文章將為大家詳細(xì)講解有關(guān)CSS中icon圖標(biāo)之純CSS如何實(shí)現(xiàn)帶動(dòng)畫效果的天氣圖標(biāo) ,小編覺(jué)得挺實(shí)用的,因此分享給大家做個(gè)參考,希望大家閱讀完這篇文章后可以有所收獲。

效果: 

CSS中icon圖標(biāo)之純CSS如何實(shí)現(xiàn)帶動(dòng)畫效果的天氣圖標(biāo)

下面我們來(lái)做一個(gè)會(huì)下雨的天氣圖標(biāo)實(shí)例,過(guò)程其實(shí)很簡(jiǎn)單哦。

CSS中icon圖標(biāo)之純CSS如何實(shí)現(xiàn)帶動(dòng)畫效果的天氣圖標(biāo)

STEP1: 整體HTML架構(gòu) 

<div class="icon rainy"> 
<div class="cloud"></div> 
<div class="rain"></div> 
</div>

STEP2: 用CSS繪制云朵圖標(biāo)
CSS代碼如下

body { 
max-width: 42em; 
padding: 2em; 
margin: 0 auto; 
color: #161616; 
font-family: 'Roboto', sans-serif; 
text-align: center; 
background-color: currentColor; 
} 
.icon { 
position: relative; 
display: inline-block; 
width: 12em; 
height: 10em; 
font-size: 1em; /* control icon size here */ 
} 
.cloud { 
position: absolute; 
z-index: 1; 
top: 50%; 
left: 50%; 
width: 3.6875em; 
height: 3.6875em; 
margin: -1.84375em; 
background: currentColor; 
border-radius: 50%; 
box-shadow: 
-2.1875em 0.6875em 0 -0.6875em, 
2.0625em 0.9375em 0 -0.9375em, 
0 0 0 0.375em #fff, 
-2.1875em 0.6875em 0 -0.3125em #fff, 
2.0625em 0.9375em 0 -0.5625em #fff; 
} 
.cloud:after { 
content: ''; 
position: absolute; 
bottom: 0; 
left: -0.5em; 
display: block; 
width: 4.5625em; 
height: 1em; 
background: currentColor; 
box-shadow: 0 0.4375em 0 -0.0625em #fff; 
} 
.cloud:nth-child(2) { 
z-index: 0; 
background: #fff; 
box-shadow: 
-2.1875em 0.6875em 0 -0.6875em #fff, 
2.0625em 0.9375em 0 -0.9375em #fff, 
0 0 0 0.375em #fff, 
-2.1875em 0.6875em 0 -0.3125em #fff, 
2.0625em 0.9375em 0 -0.5625em #fff; 
opacity: 0.3; 
transform: scale(0.5) translate(6em, -3em); 
animation: cloud 4s linear infinite; 
} 
.cloud:nth-child(2):after { background: #fff; } 
.rain{ 
position: absolute; 
z-index: 2; 
top: 50%; 
left: 50%; 
width: 3.75em; 
height: 3.75em; 
margin: 0.375em 0 0 -2em; 
background: currentColor; 
} 
.rain:after { 
content: ''; 
position: absolute; 
z-index: 2; 
top: 50%; 
left: 50%; 
width: 1.125em; 
height: 1.125em; 
margin: -1em 0 0 -0.25em; 
background: #0cf; 
border-radius: 100% 0 60% 50% / 60% 0 100% 50%; 
box-shadow: 
0.625em 0.875em 0 -0.125em rgba(255,255,255,0.2), 
-0.875em 1.125em 0 -0.125em rgba(255,255,255,0.2), 
-1.375em -0.125em 0 rgba(255,255,255,0.2); 
transform: rotate(-28deg); 
animation: rain 3s linear infinite; /*設(shè)置動(dòng)畫 rain */ 
} 
STEP3: 下雨動(dòng)畫 
/* 下雨動(dòng)畫 Animations */ 
@keyframes rain { 
0% { 
background: #0cf; 
box-shadow: 
0.625em 0.875em 0 -0.125em rgba(255,255,255,0.2), 
-0.875em 1.125em 0 -0.125em rgba(255,255,255,0.2), 
-1.375em -0.125em 0 #0cf; 
} 
25% { 
box-shadow: 
0.625em 0.875em 0 -0.125em rgba(255,255,255,0.2), 
-0.875em 1.125em 0 -0.125em #0cf, 
-1.375em -0.125em 0 rgba(255,255,255,0.2); 
} 
50% { 
background: rgba(255,255,255,0.3); 
box-shadow: 
0.625em 0.875em 0 -0.125em #0cf, 
-0.875em 1.125em 0 -0.125em rgba(255,255,255,0.2), 
-1.375em -0.125em 0 rgba(255,255,255,0.2); 
} 
100% { 
box-shadow: 
0.625em 0.875em 0 -0.125em rgba(255,255,255,0.2), 
-0.875em 1.125em 0 -0.125em rgba(255,255,255,0.2), 
-1.375em -0.125em 0 #0cf; 
} 
}

最圖效果:

CSS中icon圖標(biāo)之純CSS如何實(shí)現(xiàn)帶動(dòng)畫效果的天氣圖標(biāo)

關(guān)于“CSS中icon圖標(biāo)之純CSS如何實(shí)現(xiàn)帶動(dòng)畫效果的天氣圖標(biāo) ”這篇文章就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,使各位可以學(xué)到更多知識(shí),如果覺(jué)得文章不錯(cuò),請(qǐng)把它分享出去讓更多的人看到。

向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI