html - Flexbox tailwind:不能让子元素的宽度调整内容
问题描述
我有这个代码:
<div class = "flex-none flex-col bg-gray-500 border border-black rounded rounded p-5 ">
<div class=" border w-auto bg-gray-700 flex-none flex-col content-start justify-start ">
<div
class = "border border-red-200 w-auto inline-block flex flex-row content-start
justify-start bg-gray-900 cursor-pointer hover:bg-gray-700
border rounded border-black p-2 mt-2 ">
A
</div>
<div
class = "border border-red-200 w-auto inline-block flex flex-row content-start
justify-start bg-gray-900 cursor-pointer hover:bg-gray-700
border rounded border-black p-2 mt-2 ">
B
</div>
<div
class = "border border-red-200 w-auto inline-block flex flex-row content-start
justify-start bg-gray-900 cursor-pointer hover:bg-gray-700
border rounded border-black p-2 mt-2 ">
C
</div>
</div>
</div>
它看起来像这样:
虽然我希望它像这样将宽度调整为内容大小:
解决方案
在父容器上使用inline-flex
而不是flex
<link href="https://unpkg.com/tailwindcss@^1.0/dist/tailwind.min.css" rel="stylesheet">
<div class="flex-none flex-col bg-gray-500 border border-black rounded rounded p-5 ">
<div class=" border w-auto bg-gray-700 flex-none inline-flex flex-col content-start justify-start ">
<div class="border border-red-200 w-auto inline-block flex flex-row content-start width-auto
justify-start bg-gray-900 cursor-pointer hover:bg-gray-700
border rounded border-black p-2 mt-2 text-white ">
A
</div>
<div class="border border-red-200 w-auto inline-block flex flex-row content-start
justify-start bg-gray-900 cursor-pointer hover:bg-gray-700
border rounded border-black p-2 mt-2 text-white ">
B
</div>
<div class="border border-red-200 w-auto inline-block flex flex-row content-start
justify-start bg-gray-900 cursor-pointer hover:bg-gray-700
border rounded border-black p-2 mt-2 text-white ">
C
</div>
</div>
</div>
推荐阅读
- r - 优化 R 代码以减少迭代时间
- javascript - SAPUI5 SelectDialog中的“全选/取消全选”
- javascript - SAPUI5 - 如何获取我的自定义控件已绑定到的模型的名称?
- nginx - 同一服务器实例上多个静态站点的 Nginx 配置
- php - 获取要在 laravel 中生成的发票编号
- postgresql - 如何获取当前会话的正确时区 ID
- reactjs - 无法让 redux 组件重新渲染
- css - 如何在 Angular 7 中同时使用 css 和 sass 文件?
- python - 当参数默认为 None 时使用 __repr__,但可能是 str
- java - 如何在全球范围内忽略具有恢复响应的 Null 字段?