Parallax is a 3d effect used in various websites to make webpages attractive . In this effect, as we scroll, the background of the webpages moves at different speed than the foreground making it look brilliant to the eyes.
These websites show the parallax effect brilliantly-
This effect is a great visual but an easy method to implement with the help of CSS.
First, let us understand what is happening in the given examples.
The effect is created because the image in the background is kept fixed with no movement but other images are moving . This simple technique makes this effect look brilliant.
Now let us see the implementation of this effect using CSS-
This property is used to determine whether a background image is fixed or scroll with the page.
Syntax : background-attachment: scroll/fixed/local;
This property determines the starting position of the background image.
Syntax : background-position: value;
This property determines whether a background image will repeat or not and if repeated , how will it be repeated.
Syntax : background-repeat: repeat/repeat-x/repeat-y/no-repeat;
repeat – The background image will be repeated both vertically and horizontally.
repeat-x – The background image will be repeated only horizontally.
repeat-y – The background image will be repeated only vertically.
no-repeat – The background-image will not be repeated.
This property determines the size of the background image.
Syntax : background-size: auto/length/cover/contain/;
auto – Default value.
length – Sets the width and height of the background image.
percentage – Sets the width and height of the background image in percent of the container element.
cover – Scale the background image to be as large as possible so that the background area is completely covered by the background image.
contain – Scale the image to the largest size such that both its width and its height can fit inside the content area.