
tailwind css line-height/leading 失效?垂直居中怎么做?
在使用 Tailwind CSS 时,你可能会遇到 line-height 或 leading 设置无效的情况,特别是对于垂直居中的元素。
这个问题通常是由以下原因引起的:
解决方法:
以下是垂直居中元素的几种解决方法:
立即学习“前端免费学习笔记(深入)”;
<nav class="nav h-12 w-full">
<div class="container mx-auto flex">
<div class="flex h-12 w-24 items-center justify-center hover:bg-black hover:text-white">首页</div>
<p class="flex h-12 w-24 items-center justify-center hover:bg-black hover:text-white">首页</p>
<span class="flex h-12 w-24 items-center justify-center hover:bg-black hover:text-white">首页</span>
</div>
</nav><nav class="nav h-10 w-full">
<div class="container mx-auto flex">
<div class="h-10 w-24 text-center leading-10 hover:bg-black hover:text-white">首页</div>
<p class="h-10 w-24 text-center leading-10 hover:bg-black hover:text-white">首页</p>
<span class="h-10 w-24 text-center leading-10 hover:bg-black hover:text-white">首页</span>
</div>
</nav>.leading-12 {
line-height: 2.5rem;
}然后在你的代码中使用它:
<div class="h-12 w-24 text-center leading-12 hover:bg-black hover:text-white">首页</div>
以上就是Tailwind CSS 中 line-height/leading 失效?如何实现垂直居中?的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号