您可以使用 Tailwind CSS 中的flex属性轻松地在全屏上垂直对齐 div。 Tailwind 使用justify-center和items-center属性,这是 CSS 中 flex-property 的替代品。 句法: . . . 弹性属性: h-screen:它使元素跨越视口的整个高度,因为默认情况下所有容器都占据它们的整个宽度,但它们不会占据它们的整个高度。
使用items-center和justify-center,如下所示:
6"><div><h3class="underline font-semibold">resize-y</h3><textareaclass="resize-y w-32 h-16 p-2 border border-gray-300"placeholder="Resize vertically"></textarea><pclass="text-sm">Vertical resizing only.</p></div><div><h3class="underline font-semibold">resize-x</h3><textarea...
DOCTYPEhtml><htmllang="en"><head><scriptsrc="https://cdn.tailwindcss.com"></script></head><bodyclass="p-4"><divclass="bg-gray-300 md:bg-blue-500 text-gray-800 md:text-white p-6 rounded"><pclass="text-center">This box changes color based on screen size.</p></div></body>...
使用items-center和justify-center,如下所示:
<div class="w-full md:w-1/2 lg:w-1/3">Column 1</div> <div class="w-full md:w-1/2 lg:w-1/3">Column 2</div> <div class="w-full md:w-1/2 lg:w-1/3">Column 3</div> </div> Here, the columns will stack vertically on small screens, display in two columns on mediu...
Use.flex-col-reverseto position flex items vertically in the opposite direction: 1 2 3 <divclass="flex flex-col-reverse bg-gray-200"><divclass="text-gray-700 text-center bg-gray-400 px-4 py-2 m-2">1</div><divclass="text-gray-700 text-center bg-gray-400 px-4 py-2 m-2">2...
<div class="flex flex-col md:flex-row md:space-x-3 items-center space-y-3 md:space-y-0"> <div class="border border-gray-200 rounded"> <img src="https://via.placeholder.com/300x200.png" /> <p class="p-5">This is a card made with Bootstrap</p> </div> </div> </se...
</div> Each list item will represent a company’s logo, and we’ve added the alt attribute to every image to ensure accessibility. Theulelement has the classesflexanditems-center, which make the logos stand in a row and be vertically centered. ...
🎉 The above will center a div horizontally and vertically 🎉 Add a sizing layout class <!-- Sizing Class on the Parent --> <div class="layout-packed-mc-x w-fill w-fill"> <!-- Sizing Class on the Parent --> <div class="h-fixed-24 w-fixed-24">Hello World</div> </div...