body {
margin: 0;
height: 100%;
background-image: linear-gradient(
to bottom,
rgba(255, 255, 0, 0.5),
rgba(0, 0, 255, 0.5)
), url("img/background.jpg");
font-family: 'Montserrat', sans-serif;
font-weight: bold;
}
(https://phpout.com/wp-content/uploads/2023/07/3QrE2-jpg.webp)]
the gradient linear repeats in page 2 while it doesnt in page 1 despite the code being the same
2
Answers
You can achieve this using the
background-attachment
property.Try adding
background-attachment: fixed
in your CSS.NOTE: You have to include the
background-attachment
property AFTER all other background properties.Here is a full example:
You can learn more about the Fixed Background Attachment Hack here.
Change the height to
100vh
and set thewidth: 100%;
and also usebackground
instead ofbackground-image
as it only takes the background image nothing else. Although, browsers may not always show the error with the wrong code.And if you are applying it on 2 pages then add the stylesheet correctly in
head
section of the page then it will work for sure.