This code implements a simple parallax section with only CSS, no Javascript needed. The idea is that an image will be set as the background image of a section with fixed position, so that when people scroll down, the image stays fixed. The section should have a width defined.
There is an overlay layer on the image which we can put a darker color on the image. Text is horizontally and vertically centered, written on top of the overlay layer, so it is visible and not affected by the overlay.
HTML page (with Bootstrap included):
CSS file:
The downside of this, as far as I notice, that the background image does not stay fixed on mobile.
Result with HTML and CSS with a valid image:
Leave a Reply