Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fill the height of the viewport with tailwind css

I'm just trying out Tailwind CSS and want to know how to fill the height of the viewport.

Taking this example HTML from the docs

<div class="flex items-stretch bg-grey-lighter">
    <div class="flex-1 text-grey-darker text-center bg-grey-light px-4 py-2 m-2">1</div>
    <div class="flex-1 text-grey-darker text-center bg-grey-light px-4 py-2 m-2">2</div>
    <div class="flex-1 text-grey-darker text-center bg-grey-light px-4 py-2 m-2">3</div>
</div>

How do I make it stretch to the bottom of the screen?

like image 479
bencarter78 Avatar asked Dec 21 '17 13:12

bencarter78


People also ask

How do I change my full height in tailwind?

​ Use h-full to set an element's height to 100% of its parent, as long as the parent has a defined height.

How do I get full height of screen in CSS?

height:100vh When you set the height to 100vh, the box element will stretch its height to the full height of the viewport regardless of its parent height.

Which class is used to make the minimum height 100% in tailwind CSS ?( Documentation is calling you?

h-full: This class sets an element's height to 100% of its parent, as long as the parent has a defined height. h-screen: This class used to make an element span the entire height of the viewport.


6 Answers

There is a tailwind class named .h-screen that translates to height:100vh; css. This should work as well. For further details please refer to the Official Tailwind documentation

like image 94
Nitin Jadhav Avatar answered Sep 26 '22 20:09

Nitin Jadhav


You can use .h-screen class of Tailwind CSS.

like image 28
Sulaiman Abiodun Avatar answered Sep 28 '22 20:09

Sulaiman Abiodun


You can add min-h-screen to the parent <div>, this would fill the height of the viewpoint.

And the difference with h-screen is that this will stretch over the screen. It would be helpful when the screen is tiny and the content is overflowing with a scrollbar. In this situation the background will not fill the rest of the scrolled-up part.

 <div class="flex items-stretch bg-grey-lighter min-h-screen">
    <div class="flex-1 text-grey-darker text-center bg-grey-light px-4 py-2 m-2">1</div>
    <div class="flex-1 text-grey-darker text-center bg-grey-light px-4 py-2 m-2">2</div>
    <div class="flex-1 text-grey-darker text-center bg-grey-light px-4 py-2 m-2">3</div>
</div>

Link to some snippets at tailwind play (added a background color example to clarify it): https://play.tailwindcss.com/8Qd822yY4w

like image 32
gosentetsu Avatar answered Sep 26 '22 20:09

gosentetsu


I know it's an old post, but I found it now, while I was trying to have the background color streched to the size of the screen when the content was too little to fill it and avoid to have the background color to stop suddenly when the content was more of the size of the screen (that happens with h-screen). I solved the problem using min-h-screen.

like image 27
Simone Celli Avatar answered Sep 28 '22 20:09

Simone Celli


You may use h-screen class in your main div. Check out more here

like image 32
Foysal imran Avatar answered Sep 27 '22 20:09

Foysal imran


I'm using NextJS + tailwindcss. NextJS adds a <div id="__next">, so this is what I have in my global.css

@tailwind base;
@tailwind components;
@tailwind utilities;
html {
  @apply h-full;
}
body {
  @apply h-full;
}
div#__next {
  @apply h-full;
}
main {
  @apply h-full;
}

And in my page I have

<main className="bg-gradient-to-br from-indigo-500 via-purple-500 to-pink-500">
  ...
</main>
like image 34
Jonathan Morales Vélez Avatar answered Sep 27 '22 20:09

Jonathan Morales Vélez