html - Tailwind CSS - 无法在 div 内居中搜索栏
问题描述
我想在父 div 内居中搜索栏,但它不起作用。我尝试在父 div 上使用 flex 和 justify-center,但它不仅不居中,而且还缩小了我的搜索栏的 div。我认为这是因为不允许将类 flex 嵌套在彼此内部,所以我尝试了 text-center 但这也没有用。
我查看的一些链接:
代码:
<div>
<div className="flex items-center max-w-md shadow rounded border-0 p-3">
<input type="search" className="flex-grow py-2" placeholder="Search by name..." />
<i className="fas fa-search flex-grow-0 py-2 px-2" />
</div>
</div>
解决方案
该类max-w-md
限制了div
它所应用的宽度,但它并不以div
自身为中心。为此,请添加mx-auto
类:
<div className="flex items-center max-w-md mx-auto shadow rounded border-0 p-3">
推荐阅读
- javascript - 对 Autodesk Forge Viewer 实施 ThreeJS Transform 控件
- python - 在 AWS 中添加侦听器规则时添加查询字符串参数或 cookie
- javascript - Javascript - 按字符串索引属性对字符串数组进行排序
- android - 为什么我的自定义视图中的数据绑定不起作用?
- javascript - 尽管设置了 .innerHTML,textarea 仍为空
- sql-server - 从 SQL Server XML 数据类型中提取 XML 元素作为字符串
- jquery - 当我在 jsp 中使用 jQuery 日期选择器时,日期不会保存在 Mysql 中
- git - 使预提交挂钩忽略子模块
- amazon-web-services - 如何让我的 Apache 负载均衡器为 index.html 提供服务?
- vb.net - 如何区分没有扩展名的文件夹和文件?