DEV Community

Cover image for Image Parallex Effect with CSS
Shubham Tiwari
Shubham Tiwari

Posted on • Edited on

Image Parallex Effect with CSS

Hello Everyone today i will show your how to create parallex effect with css.

Let's get started...

  • To create a parallex effect, we need to set the container height like 100vh or whatever height you want.
  • Then applying the background image using the background-image property.
  • To fix the background image on it's position we will use background-attachment property and will set it value to fixed.Example is below
.container{
height:100vh;
background-repeat: no-repeat;
background-attachment: fixed;
background-position: center;
background-size:cover;
}
Enter fullscreen mode Exit fullscreen mode
  • I didn't applied the background-image property in the container because we will be having multiple container and each container will have different background image,we can create a seperate class for creating unique container like this.
<div class="container container-1"></div>
<div class="container container-2"></div>
<div class="container container-3"></div>
Enter fullscreen mode Exit fullscreen mode
  • You can set the background image to the containers separately using their second class name like this.
.container-1{
background-image:url("image-1-url")
}
.container-2{
background-image:url("image-2-url")
}
.container-3{
background-image:url("image-3-url")
}
Enter fullscreen mode Exit fullscreen mode

Codepen -

THANK YOU FOR CHECKING THIS POST
You can contact me on -
Instagram - https://www.instagram.com/supremacism__shubh/
LinkedIn - https://www.linkedin.com/in/shubham-tiwari-b7544b193/
Email - shubhmtiwri00@gmail.com

^^You can help me by some donation at the link below Thank you👇👇 ^^
☕ --> https://www.buymeacoffee.com/waaduheck <--

Also check these posts as well
https://dev.to/shubhamtiwari909/css-iswherehas-and-not-2afd

https://dev.to/shubhamtiwari909/theme-changer-with-html-and-css-only-4144

https://dev.to/shubhamtiwari909/swiperjs-3802

https://dev.to/shubhamtiwari909/going-deep-in-array-sort-js-2n90

Top comments (0)