I want to have a background gradient, e.g.
background: linear-gradient(to bottom, rgba(0, 0, 0, 0.3), rgba(2, 126, 174, 0.9))
on the body of my document which extends across the entire height of the body - and scrolls with the body.
Using
background-attachment: fixed;
I get the entire height (of the viewport), but it, well, stays fixed.
background-attachment: scroll;
gets me the scrolling, but then it just extends across the viewport height.
Any way to get both?
Edit:
As Boltclock pointed out, I do get the expected behavior with 'background-attachment: scroll' on a basic test page.
With
<body>
<div id="stretch">Content</div>
</body>
and
body {
background: linear-gradient(to bottom, rgba(0, 0, 0, 0.3), rgba(2, 126, 174, 0.9));
}
#stretch {
height: 2000px;
}
everything works fine: The gradient extends across the entire body (and the body is 2000px tall), and scrolls with the content.
Then I add
html,
body {
height: 100%;
}
This is something which the basic template the page is based on does.
In order to get the body to expand again, I add
height: auto;
and the body is back to 2000px height.
However, the gradient remains at the HTML height - and repeats then.
What am I missing here?
background-attachment: scroll
is the default. If the body is taller than the viewport, your gradient declaration alone should be enough, unless I'm missing something. – BoltClock