I have an animated background that I would like to display behind some text without having to resort to javascript. The text may overflow beyond the viewport. I want the background div to always be the same height as the div containing the text, and I want to achieve this without having to resort to Javascript. Is this possible?
Here is a code sandbox demonstrating my failed attempt:
https://codesandbox.io/s/div-over-div-height-matching-with-only-css-phvejg
And here is the HTML/css snippet in question:
<div className="w-screen h-screen">
<LongBackgroundAnimation />
<div className="absolute top-0 z-10 m-8 backdrop-blur">
<p className="">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad
minim veniam, quis nostrud exercitation ullamco laboris nisi ut
aliquip ex ea commodo consequat. Duis aute irure dolor in
reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla
pariatur. Excepteur sint occaecat cupidatat non proident, sunt in
culpa qui officia deserunt mollit anim id est laborum.
</p>
</div>
</div>
2
Answers
I put it in a
grid
and with both grid items in column 1 and row 1, so they are stacked on top of each other.You have a somewhat incorrect approach. If the canvas should be used as a background, then it should be specified as an
position: absolute
: