純CSS實(shí)現(xiàn)天氣預(yù)報(bào)

<!-- Teemo -->

<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="UTF-8">

<title>CSS實(shí)現(xiàn)天氣</title>

<style type="text/css">

.weather{

position: relative;

display: inline-block;

width: 180px;

height: 240px;

background: #23b7e5;

border-radius: 8px;

}

.sunny:before{

content: "";

position: absolute;

top: 50%;

left: 50%;

transform: translate(-50%,-50%); /*定位、旋轉(zhuǎn)等*/

width: 60px;

height: 60px;

background: #F6D963;

border-radius: 50%;

box-shadow: 0 0 20px #ff0; /*陰影-外發(fā)光效果;水平-上下-大小-顏色*/

z-index: 2;/*設(shè)置元素的堆疊順序。擁有更高堆疊順序的元素總是會(huì)處于堆疊順序較低的元素的前面;分層顯示*/

}

.sunny:after{

content: "";

position: absolute;

top: 50%;

left: 50%;

margin: -45px 0 0 -45px;

width: 90px;

height: 90px;

background: #FFEB3B;

clip-path: polygon(? /*繪制圖形*/

50% 0%,

65.43% 25%,

93.3% 25%,

78.87% 50%,

93.3% 75%,

64.43% 75%,

50% 100%,

35.57% 75%,

6.7% 75%,

21.13% 50%,

6.7% 25%,

35.57% 25%

);

z-index: 1;

animation: sunScale 2s linear infinite;/*實(shí)現(xiàn)動(dòng)畫*/

}

@keyframes sunScale {

0%{

transform: scale(1);

}

50%{

transform: scale(1.1);

}

100%{

transform: scale(1);

}

}

.cloudy:before,.rainy:before,.snowy:before{

content: "";

position: absolute;

top: 50%;

left: 25%;

transform: translate(-50%,-50%);

width: 36px;

height: 36px;

background: #fff;

border-radius: 50%;

z-index: 2;

box-shadow: #fff 22px -15px 0 6px,

#fff 57px -6px 0 2px,

#fff 87px 4px 0 -4px,

#fff 33px 6px 0 6px,

#fff 61px 6px 0 2px,

#ccc 29px -23px 0 6px,

#ccc 64px -14px 0 2px,

#ccc 94px -4px 0 -4px;

}

/*box-shadow: h-shadow v-shadow blur spread color inset;

參數(shù)詳解:

h-shadow: 陰影的水平偏移量。

v-shadow: 陰影的垂直偏移量。

blur: 模糊距離(就是漸變的距離,設(shè)為0就沒有漸變)。

spread: 投影的尺寸,通過這個(gè)控制“影分身”的大小。

color: 投影顏色,通過這個(gè)實(shí)現(xiàn)后方的烏云。

inset: 改為內(nèi)陰影。這里用不到。*/

.cloudy:before{

animation: cloudMove 2s linear infinite;

}

@keyframes cloudMove {

0%{

transform: translate(-50%,-50%);

}

50%{

transform: translate(-50%,-60%);

}

100%{

transform: translate(-50%,-50%);

}

}

.rainy:after {

/*這里使用 :after 偽類實(shí)現(xiàn)雨滴。

先實(shí)現(xiàn)一個(gè)雨滴(為方便觀看,暫時(shí)隱藏云朵):*/

? content: "";

? ? position: absolute;

top:50%;

left: 25%;

width: 4px;

height: 14px;

background: #fff;

border-radius: 2px;

/*然后通過box-shadow“影分身”:*/

box-shadow:

#fff 25px -10px 0,

#fff 50px 0 0,

#fff 75px -10px 0,

#fff 0 25px 0,? ? ? ?

#fff 25px 15px 0,? ? ? ?

#fff 50px 25px 0,? ? ? ?

#fff 75px 15px 0,

#fff 0 50px 0,

#fff 25px 40px 0,

#fff 50px 50px 0,

#fff 75px 40px 0;

animation: rainDrop 2s linear infinite;

}

@keyframes rainDrop {

0% {

transform: translate(0,0) rotate(10deg);

}

100% {

transform: translate(-4px,24px) rotate(10deg);

box-shadow:

#fff 25px -10px 0,

#fff 50px 0 0,

#fff 75px -10px 0,

#fff 0 25px 0,

#fff 25px 15px 0,

#fff 50px 25px 0,

#fff 75px 15px 0,

rgba(255,255,255,0) 0 50px 0,

rgba(255,255,255,0) 25px 40px 0,

rgba(255,255,255,0) 50px 50px 0,

rgba(255,255,255,0) 75px 40px 0;

? ? }

}

.snowy:after {

content: "";

position: absolute;

top: 50%;

left: 25%;

width: 8px;

height: 8px;

background: #fff;

border-radius: 50%;

box-shadow:

#fff 25px -10px 0,

#fff 50px 0 0,

#fff 75px -10px 0,

#fff 0 25px 0,

#fff 25px 15px 0,

#fff 50px 25px 0,

#fff 75px 15px 0,

#fff 0 50px 0,

#fff 25px 40px 0,

#fff 50px 50px 0,

#fff 75px 40px 0;

animation: snowDrop 2s linear infinite;

}

@keyframes snowDrop {

0% {

transform: translateY(0);

}

100% {

transform: translateY(25px);

box-shadow:

#fff 25px -10px 0,

#fff 50px 0 0,

#fff 75px -10px 0,

#fff 0 25px 0,

#fff 25px 15px 0,

#fff 50px 25px 0,

#fff 75px 15px 0,

rgba(255,255,255,0) 0 50px 0,

rgba(255,255,255,0) 25px 40px 0,

rgba(255,255,255,0) 50px 50px 0,

rgba(255,255,255,0) 75px 40px 0;

}

}

</style>

</head>

<body>

<!-- 晴 -->

<div class="weather sunny"></div>

<!-- 陰 -->

<div class="weather cloudy"></div>

<!-- 雨 -->

<div class="weather rainy"></div>

<!-- 雪 -->

<div class="weather snowy"></div>

</body>

</html>


https://mp.weixin.qq.com/s?__biz=MzA5MjQ0Mjk2NA==&mid=2247484765&idx=1&sn=f9ea87dea436fc3392f731491d9c8507&chksm=906c5d66a71bd470588069025888cb6cb87551a0a878245d2e2ba8c98bba40087993ebd25481&mpshare=1&scene=1&srcid=&sharer_sharetime=1564704745722&sharer_shareid=5c25a9bf1f137b3812e262b3174891a5&key=f6d26f92f2a2f56d0259e23dac5cfbce8ca819190772aa3c79663cee09c87c4c68cfa49d7ba338a890e2f4b2474f82f1313c2775c2cd588a641b1fdff422dffe834339fcee6b18f6a1fbd912ed7a20ad&ascene=1&uin=MTQ2OTA3MTkwNQ%3D%3D&devicetype=Windows+7&version=62060833&lang=zh_CN&pass_ticket=QgFeq12VxyQlMfi4nUypDPFz%2F3AgcPmoOgvDpcolxJOcIhpVdThdrDbhO%2BwwwKfh

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

友情鏈接更多精彩內(nèi)容