Weather Animated Icon using HTML and CSS

In this article, we will create different types of weather icon such as sun, cloud, snow, cloud with rain. Earlier I have shared a blog Snow-Fall Animation Using HTML and CSS.

HTML Code:

<!DOCTYPE html>
<html lang="en">
<!--www.codeithub.com-->
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Weather Report | Codeithub</title>
    <link rel="stylesheet" href="style.css">
</head>

<body>
    <h1>Weather Report</h1>
    <div class="container">
        <div class="weather-sun">
            <div class="sun">
                <div class="rays"></div>
                <div class="rays"></div>
                <div class="rays"></div>
                <div class="rays"></div>
            </div>
        </div>
        <div class="weather-cloud">
            <div class="cloud"></div>
            <div class="cloud"></div>
        </div>
        <div class="weather-snow">
            <div class="snow">
                <div class="f"></div>
            </div>
        </div>
        <div class="weather-cloudAndSun">
            <div class="cloud"></div>
            <div class="sun">
                <div class="rays"></div>
                <div class="rays"></div>
                <div class="rays"></div>
                <div class="rays"></div>
            </div>
        </div>
        <div class="weather-rain">
            <div class="cloud"></div>
            <div class="rain"></div>
            <div class="rain"></div>
            <div class="rain"></div>
            <div class="rain"></div>
        </div>
    </div>
</body>

</html>

CSS Code:

/*www.codeithub.com*/
h1{
    font-size: 4em;
    text-align: center;
    padding-top: 5px;
    color: #113744;
    margin: 0;
    font-style: oblique;
}
body{
    background: #CDEDF8;
}

.container{
    width: 700px;
    height: 100vh;
    margin: 0 auto;
}

.weather-sun,.weather-cloud,.weather-snow,.weather-cloudAndSun,.weather-rain{
    width: 200px;
    height: 200px;
    display: inline-block;
    position: relative;
}

.weather-cloudAndSun,.weather-rain{
    margin-left: 60px;
}

.sun{
    width: 100px;
    height: 100px;
    background: linear-gradient(49deg,#e9dd71,#e6bc34);
    border-radius: 100%;
    transform: rotate(0deg);
    animation: xuanzhuang 8s infinite linear;
    position: absolute;
    left: 50%;
    top: 50%;
}

.rays{
    width: 7px;
    height: 13px;
    background: #e9dd71;
    position: absolute;
    transform: translateX(-60%);
    left: 50%;
    top: -25px;
    box-shadow: 0 135px #e9dd71;
    border-radius: 4px;
    transform-origin: 0px 75px;
}

.rays:nth-child(2){
    transform: rotate(45deg);
}

.rays:nth-child(3){
    transform: rotate(90deg);
}

.rays:nth-child(4){
    transform: rotate(135deg);
}

@keyframes xuanzhuang {
    100% { transform: rotate(360deg); }
}
.cloud{
    border-radius: 25px;
    position: absolute;
    top: 70%;
    left: 50%;
    width: 150px;
    height: 50px;
    background: #4b93ac;
}

.cloud:nth-child(2){
    left: 200px;
    width: 100px;
    height: 30px;
    background: #4b93ac;
    opacity: 1;
    animation: cloud 6s linear infinite;
}

.cloud::after,.cloud::before{
    content: '';
    display: block;
    background: #4b93ac;
    border-radius: 50%;
    position: absolute;
    
}

.cloud:nth-child(2)::after,.cloud:nth-child(2)::before{
    content: '';
    display: block;
    background: #4b93ac;
    border-radius: 50%;
    position: absolute;
    
}

.cloud::after{
    width: 80px;
    height: 80px;
    left: 45px;
    top: -45px;
}

.cloud::before{
    width: 60px;
    height: 60px;
    top: -10px;
    left: 0;
}

.cloud:nth-child(2)::after{
    width: 50px;
    height: 50px;
    left: 35px;
    top: -30px;
}

.cloud:nth-child(2)::before{
    width: 40px;
    height: 40px;
    top: -10px;
    left: 0px;
}

@keyframes cloud {
    0% { 
        opacity: 0; 
    }
    50% { 
        opacity: 1; 
    }
    100% {
        opacity: 0;
        transform: scale(0.8) translateX(-200%);
    }
}

.snow{
    width: 150px;
    height: 10px;
    border-radius: 5px;
    background: white;
    transform: rotate(0deg);
    position: absolute;
    top: 70%;
    left: 60%;
    animation: Rotate 10s infinite linear;
    position: relative;
}

.snow::after,.snow::before{
    content: '';
    width: 150px;
    height: 10px;
    border-radius: 5px;
    background: white;
    position: absolute;
}

.snow::after{
    transform: rotate(60deg);
}

.snow::before{
    transform: rotate(120deg);
}

.f{
    width: 28px;
    height: 10px;
    border-radius: 5px;
    position: absolute;
    background: white;
    top: -45px;
    left: 25px;
    box-shadow: 0px 90px white,72px 90px white,72px 0px white;
}

.f::after,.f::before{
    content: '';
    width: 28px;
    height: 10px;
    transform: rotate(60deg);
    border-radius: 5px;
    position: absolute;
    background: white;
    top: -10px;
    left: 55px;
    box-shadow: 0px 90px white,72px 90px white,72px 0px white;
}

.f::before{
    transform: rotate(120deg);
    left: 15px;
    box-shadow: 72px 0px white,72px -90px white,0px -90px white;
}

@keyframes Rotate {
    100% { transform: rotate(360deg); }
}

.weather-cloudAndSun .cloud{
    z-index: 1;
    opacity: 0.95;
}

.weather-cloudAndSun .sun{
    position: absolute;
    left: 180px;
    top: 60px;
    z-index: 0;
}

.rain{
    width: 4px;
    height: 34px;
    background:linear-gradient(transparent,lightblue);
    position: absolute;
    left: 210px;
    top: 170px;
    border-radius: 2px;
    animation: rainning 1s infinite;
}

.rain:nth-child(2){
    height: 20px;
    left: 190px;
    top: 190px;
}

.rain:nth-child(3){
    height: 50px;
    left: 170px;
    top: 180px;
}

.rain:nth-child(4){
    height: 25px;
    left: 150px;
    top: 185px;
}

@keyframes rainning{
    100%{
        top: 200px;
    }
}

OUTPUT

See also  How to create calculator using JavaScript?

Leave a Reply

Your email address will not be published. Required fields are marked *