I’m trying to add a gradient to my background using CSS. I want this gradient to not be ‘fixed’, but scroll with the page. For very tall pages, I just want the gradient to end.
This is my CSS:
body {
min-height: 100%;
background-color: #F00;
background-repeat: no-repeat;
background: linear-gradient(
180deg,
#F00 0px,
#0F0,
#00F,
#F00 3000px
)
}
The problem is that when I scroll down, after the page fold the gradient starts over. On my 1200px height screen, it never turns blue.
My goal is for the gradient to render once and if the page is larger than the gradient (lets say 3000px) for it to just be #F00
forever. No-repeat had no effect.
2
Answers
You can set background-image and background-color separately.
Your code was fine but you are facing the background propagation to the html element. Add any background-color to html to fix this and you don’t need to set
background-repeat
orbackground-size
orbackground-color
to the body element