【发布时间】:2019-07-30 02:10:24
【问题描述】:
如何将 div 与 Tailwind 垂直对齐? 我想要什么:
-----------------------------------
| |
| |
| |
| item1 |
| item2 |
| |
| |
| |
-----------------------------------
我目前拥有的:
-----------------------------------
| item1 |
| item2 |
| |
| |
| |
| |
| |
| |
-----------------------------------
HTML
<div class="flex flex-col h-screen my-auto items-center bgimg bg-cover">
<h3 class="text-white">heading</h3>
<button class="mt-2 bg-white text-black font-bold py-1 px-8 rounded m-2">
call to action
</button>
</div>
CSS
.bgimg {
background-image: url('https://d1ia71hq4oe7pn.cloudfront.net/photo/60021841-480px.jpg');
}
我已成功以 items-center 类在辅助轴(左右)上居中。阅读文档,我尝试了align-middle,但它不起作用。我已确认 div 具有完整高度和 my-auto。
我正在使用这个版本的 Tailwind:https://cdn.jsdelivr.net/npm/tailwindcss/dist/tailwind.min.css
这是一个 JSFiddle:https://jsfiddle.net/7xnghf1m/2/
【问题讨论】:
-
这已经在 TailwindCSS 文档中有很好的记录:tailwindcss.com/docs/flexbox-align-items/#center
标签: tailwind-css