简体   繁体   English

如何使用 TailwindCSS 填充剩余的屏幕高度

[英]How to fill up the rest of the screen height using TailwindCSS

I'm using Vue with Tailwind and want to create a "NotFound" view page.我正在使用带有 Tailwind 的 Vue 并想创建一个“NotFound”视图页面。 The content on this router view should be in the center on the screen.此路由器视图上的内容应位于屏幕中央。 Above the router view is a navbar component so I have to take care for the height when centering it.路由器视图上方是导航栏组件,因此在居中时我必须注意高度。

First, I tried to use h-screen for the router view首先,我尝试使用h-screen作为路由器视图

 <link href="https://unpkg.com/tailwindcss@1.8.12/dist/tailwind.min.css" rel="stylesheet"/> <div> <div class="bg-yellow-400 py-8"> my navbar </div> <div class="bg-green-400 flex justify-center items-center h-screen"> this content is not centered on screen </div> </div>

but as you can see the content in the green container is not in the center of the screen.但是正如您所看到的,绿色容器中的内容不在屏幕中央。 Next I tried to work with h-full接下来我尝试使用h-full

 <link href="https://unpkg.com/tailwindcss@1.8.12/dist/tailwind.min.css" rel="stylesheet" /> <div class="h-screen"> <div class="bg-yellow-400 py-8"> my navbar </div> <div class="bg-green-400 flex justify-center items-center h-full"> this content is not centered on screen </div> </div>

but unfortunately this still doesn't fix it.但不幸的是,这仍然不能解决它。 Does someone know how to correctly fill up the rest of the screen height so the router view will have a height of 100% - navbarComponentHeight ?有人知道如何正确填充屏幕高度的其余部分,以便路由器视图的高度为100% - navbarComponentHeight吗?

Use flexbox like below:使用 flexbox 如下:

 <link href="https://unpkg.com/tailwindcss@1.8.12/dist/tailwind.min.css" rel="stylesheet"/> <div class="flex flex-col h-screen"> <div class="bg-yellow-400 py-8"> my navbar </div> <div class="bg-green-400 flex justify-center items-center flex-grow"> this content is not centered on screen </div> </div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM