Reputation: 16742
How do you set the full page background in Tailwind?
The only attribute I can see to use is h-screen
, but that doesn't work when I resize the browser.
Here's my code:
<body class="h-screen bg-gradient-to-b from-gray-100 to-gray-300">
Full html example:
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>lkjh</title>
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="stylesheet" href="css/main.css">
</head>
<body class="h-screen bg-gradient-to-b from-gray-100 to-gray-300">
<br />a<br />a<br /><br /><br /><br /><br /><br />a<br /><br /><br /><br />a<br /><br /><br />a<br /><br />a<br />a<br />a<br />a<br />a<br />
</body>
</html>
css file
@tailwind base;
@tailwind components;
@tailwind utilities;
"tailwindcss": "npm:@tailwindcss/postcss7-compat@^2.0.2"
Upvotes: 27
Views: 57072
Reputation: 1
The gradient background should be applied to the entire viewport without expanding beyond it update your index.html file add
min-h-screen overflow-hidden = to prevent accidental overflow due to child elements
Upvotes: 0
Reputation: 24912
change h-screen
to min-h-screen
.
h-screen
:takes height of the viewport.
Now the `total height` is `viewport height + scrolled height`
👆 👆
h-screen extra height
So it doesn't expand itself to have height of the entire screen during scroll, So this can be overcomed by using min-h-screen
, meaning minimum should be the viewport height and in the occurance of scroll , expand yourself to have maximum possible height.
Upvotes: 10