Parallax Effect With HTML and CSS
In this blog I'm gonna teach you that how you can create parallax effect in your website using only HTML and CSS.
Below take a peek at the final result.
Slide through the Instagram post to see the final result.
This tutorial is gonna be so simple that you require only very basic knowledge of HTML and CSS.
here's our code you can copy paste it to play with it:
HTML code :
STEP : 1
Create a section or devision of width 100% and height 100vh (in case you don't know what vh means it's viewport height.)
Example :
<section>
<!-- its the section where we gonna apply the parallax effect -->
</section>
STEP : 2
apply css as follows to that element that we've created.(assuming we have provided that element the class as container )
.section {
background: url('image.png');
background-size: cover;
background-position: center;
background-attachment: fixed; /* Its the major property which does all the work we want */
}
background-attachment: fixed -- fixes the background at viewport and restrict its scrolling.
CSS code :
Comments
Post a Comment
if you've any doubts or queries you're free to ask