cold rainy night and hot tea cup animation by Learn code free online.
welcome to the HTML CSS tutorial by PRGTI free coder. here we are learning css by creating some amazing
animations. As everyone knows, nothing is more relaxing than to sit in front of the window while sipping
a nice hot tea and listening to the rhythmic rain showers outside. Here we are trying to create this
scenerio with the help of HTML, CSS,SVG and JS. we are gonna use city silhouette and tea cup svg images and rest is designed
completely with CSS. if you want to make tea cup with css then check here: Hot tea cup using CSS only.
Here is HTML code and little bit of Javascript code(at the end). Create a new page in any html code
editor, (I'm using visual studio code, trust me it's best for beginners.) and you can copy-paste this
code in your html page, but it's always better to write down by yourself to learn css.
so let's start with the html code. first we'll design the city silhouette
always give a class to body tag it's a good practice, it prevents lots of problems in coding. here is the
css code for building svg image and body tag:
.raininginwindow{
margin: 0;
padding: 0;
width: 100vw;
height: 100vh;
background-color: black;
background: linear-gradient(180deg, rgba(0,0,1,1) 0%, rgba(0,15,177,0.9360119047619048) 100%);
background-size: contain;
perspective: 50em;
display: flex;
perspective-origin: 50% calc(50%-2em);
z-index: -1;
overflow-x: hidden;
}
svg{
position: absolute;
bottom: -200px;
}
.city{
width: 100vw;
z-index: 0;
}
after city we will go for hot tea cup and it's steaming, we are using four divs elements to show steaming
over tea, see the below html code:
now we'll see the css styling for hot tea cup and it's steam.. we are giving div element a steam like shape
with border property. you can use clip path property too here. that will be more easy to show different
sizes of steam, but here we will use border and will apply animation with transform using keyframes
property. see the code below:
.steam1{
position:absolute;
left:370px;
top:570px;
width:15px;
height: 70px;
transform:rotate(-15deg);
background-color:transparent;
border-radius: 10% 50% 130px 0px;
border-right: 30px solid rgba(232, 225, 225, 0.4);
filter:blur(15px);
z-index: 6;
animation: steaming1 6s linear infinite 1s;
opacity: 0;
}
@keyframes steaming1{
10%{
opacity: 1;
}
100%{
transform: translateY(-200px) translateX(20px);
opacity: 0;
filter: blur(15px);
}
}
@keyframes steaming2{
10%{
opacity: 1;
}
100%{
transform: translateY(-200px) translateX(-20px);
opacity: 0;
filter: blur(15px);
}
}
.steam2{
position:absolute;
left:370px;
top:570px;
width:15px;
height: 70px;
transform:rotate(20deg);
background-color:transparent;
border-radius: 50% 10% 0px 130px;
border-left: 30px solid rgba(232, 225, 225, 0.4);
filter:blur(15px);
z-index: 6;
animation: steaming2 6s linear infinite 2s;
opacity: 0;
}
.steam3{
position:absolute;
left:370px;
top:570px;
width:15px;
height: 70px;
transform:rotate(-15deg);
background-color:transparent;
border-radius: 10% 50% 130px 0px;
border-right: 30px solid rgba(232, 225, 225, 0.4);
filter:blur(15px);
z-index: 6;
animation: steaming2 6s linear infinite 3s;
opacity: 0;
}
.steam4{
position:absolute;
left:370px;
top:570px;
width:15px;
height: 70px;
transform:rotate(20deg);
background-color:transparent;
border-radius: 50% 10% 0px 130px;
border-left: 30px solid rgba(232, 225, 225, 0.4);
filter:blur(15px);
z-index: 6;
animation: steaming1 6s linear infinite 4s;
opacity: 0;
}
here is html code for rain. we are putting rain animation in a div named box.
here we will use javascript code to animate rain. create div element with creatElement property and ada
class "rain" into it. we are using "math.random" property to create random rain drops.
css for raining animation, height of the element where rain animation going to be reside should be more than
viewport height in size i.e. 120vh.
/* raining */
.box{
width:100vw;
height: 120vh;
position: absolute;
top: 0;
left: 0;
overflow: hidden;
animation-fill-mode: forwards;
display:table;
background-color:transparent;
z-index: 1;
}
.rain{
animation: fall linear forwards;
color: rgb(255, 255, 255);
position:absolute;
top: -100px;
z-index: 99999;
width: 2px;
height: 100px;
background-color: rgba(203, 211, 218,.7);
}
@keyframes fall{
to{
transform: translateY(130vh);
}
}
now the next one is window frame, window doors and wall below the window. see the below html code:
css for window frame, wall and window doors. use groove border to div look like window frame. see the
setting of z-indexs in below so that divs can overlay properly on each other. we are using ::after and
::before pseudo elements to create window door frames. transform-origin is essential property here for doors
to look like open to outside.
.window{
width: 100vw;
height: 730px;
border-left: 45px groove rgb(2, 106, 99);
border-right: 45px groove rgb(2, 106, 99);
border-bottom: 45px groove rgb(2, 106, 99);
position: absolute;
top: 0;
left: 0px;
z-index: 2;
}
.wall{
width: 100vw;
height: 200px;
position: absolute;
top: 725px;
left: 0px;
background-color:rgb(1, 57, 57);
z-index:4;
}
.door1{
position: absolute;
top: 0px;
right: 0px;
width:370px;
height:680px;
border: 45px solid rgb(73, 116, 112);
z-index: 2;
background-size: 1em 1em;
background-color: rgba(29, 57, 54, .6);
transform:skewY(-10deg) rotateY(-60deg);
transform-origin: 100% 50% 0px;
}
.door1::before{
content: '';
width:350px;
height:60px;
background-color: rgb(73, 116, 112);
position: absolute;
top: 300px;
}
.door1::after{
content: '';
width:45px;
height:45px;
border-radius: 50%;
box-shadow: 10px 10px 5px 0px rgba(0,0,0,0.75);
background: radial-gradient(circle, rgba(106,156,141,0.9808298319327731) 0%, rgba(24,55,48,0.8575805322128851) 32%);
position: absolute;
top: 300px;
left: -20px;
}
.door2{
position: absolute;
top: 23px;
left: -200px;
width:370px;
height:680px;
border: 45px solid rgb(73, 116, 112);
z-index: 2;
background-size: 1em 1em;
background-color: rgba(29, 57, 54, .6);
transform:skewY(10deg) rotateY(60deg);
transform-origin: 100% 50% 0px;
}
.door2::before{
content: '';
width:320px;
height:60px;
background-color: rgb(73, 116, 112);
position: absolute;
top: 300px;
}
.door2::after{
content: '';
width:45px;
height:45px;
border-radius: 50%;
box-shadow: 10px 10px 5px 0px rgba(0,0,0,0.75);
background: radial-gradient(circle, rgba(106,156,141,0.9808298319327731) 0%, rgba(24,55,48,0.8575805322128851) 32%);
position: absolute;
top: 300px;
right: -20px;
}
now the last piece of html code is for curtains..see the below code:
and here is css code for the animation of curtains. We are using "repeating-radial-gradient" to create
design on curtains here. you can use any
background image or background-color to look better. here we have focused on not using any images that
already placed somewhere on the internet by someone else and see our curtains are looking absolutely
fabulous..isn't it?
.curton1{
position: absolute;
top: -200px;
right:-10px;
display: inline-flex;
height:990px;
width: 550px;
background: repeating-radial-gradient(circle, rgba(0, 255, 242, 0.614) 50%, rgba(1, 28, 28, .8) 70%);
opacity: .5;
transform-style: preserve-3d;
background-size: 2em 2em;
clip-path: polygon(100% 0, 47% 0, 47% 13%, 48% 30%, 51% 46%, 55% 67%, 55% 89%, 50% 100%, 100% 100%);
animation: ray1 4s ease-in-out infinite;
z-index: 5;
}
.curton2{
position: absolute;
top: -200px;
left:0px;
display: inline-flex;
height:990px;
width: 550px;
background: repeating-radial-gradient(circle, rgba(0, 255, 242, 0.614) 50%, rgba(1, 28, 28, .8) 70%);
opacity: .5;
transform-style: preserve-3d;
background-size: 2em 2em;
clip-path: polygon(0 0, 65% 0, 60% 23%, 55% 42%, 48% 63%, 43% 81%, 42% 91%, 43% 100%, 0 100%);
animation: ray2 4s ease-in-out infinite;
z-index: 5;
}
@keyframes ray1{
0%{
}
50%{
clip-path: polygon(100% 0, 47% 0, 44% 17%, 43% 30%, 44% 48%, 46% 72%, 49% 92%, 50% 100%, 100% 100%);
}
100%{
clip-path: polygon(100% 0, 47% 0, 47% 13%, 48% 30%, 51% 46%, 55% 67%, 55% 89%, 50% 100%, 100% 100%);
}
}
@keyframes ray2{
0%{
}
50%{
clip-path: polygon(0 0, 55% 0, 56% 23%, 55% 42%, 54% 67%, 57% 91%, 58% 99%, 59% 100%, 0 100%);
}
100%{
clip-path: polygon(0 0, 65% 0, 60% 23%, 55% 42%, 48% 63%, 43% 81%, 42% 91%, 43% 100%, 0 100%);
}
}
Copyright2022 Learn code free online. All Rights Reserved.