html - 为什么我的 flex-row 不能在我的内部 div 上工作
问题描述
我目前正在尝试将两个 div 水平相邻放置,我的想法是利用 flexbox,但添加属性flex-row
似乎没有任何作用,我不知道为什么。
如何正确地将包含“测试”的 div 水平对齐?
.card {
width: 300px;
height: 200px;
border-radius: 4px;
border-width: 1px;
border-color: lightgrey;
background-color: orangered;
}
.card-body {
width: 90%;
height: 90%;
background-color: blue;
}
.media {
width: 100%;
border-color: lightgrey;
}
<link href="https://unpkg.com/tailwindcss@0.5.2/dist/tailwind.min.css" rel="stylesheet" />
<div class="card mx-auto flex justify-center">
<div class="card-body my-auto">
<div class="media bg-blue-600 flex-row">
<div class="media-thumb w-10 h-10 bg-yellow-600 rounded-sm mx-auto">
<p>Test</p>
</div>
<div class="media-body w-10 h-10 bg-red-600 rounded-sm mx-auto">
<p>test</p>
</div>
</div>
</div>
</div>
解决方案
您只需要更改父容器中的类flex-row
的类flex
。请参阅下面的工作片段:
.card {
width: 300px;
height: 200px;
border-radius: 4px;
border-width: 1px;
border-color: lightgrey;
background-color: orangered;
}
.card-body {
width: 90%;
height: 90%;
background-color: blue;
}
.media {
width: 100%;
border-color: lightgrey;
}
<link href="https://unpkg.com/tailwindcss@0.5.2/dist/tailwind.min.css" rel="stylesheet" />
<div class="card mx-auto flex justify-center">
<div class="card-body my-auto">
<div class="media bg-blue-600 flex">
<div class="media-thumb w-10 h-10 bg-yellow-600 rounded-sm mx-auto">
<p>Test</p>
</div>
<div class="media-body w-10 h-10 bg-red-600 rounded-sm mx-auto">
<p>test</p>
</div>
</div>
</div>
</div>
推荐阅读
- flutter - 如何在颤动中使用 bloc 实现 websocket_channel
- javascript - 如何通过 jquery-confirm 插件从 confim 对话框中获取布尔结果?
- powershell - 外壳 | 选择字符串模式 + 模式下的线
- c# - 匹配签名哈希以匹配应用程序代码中的哈希以进行单元测试
- amazon-s3 - 扩展 Kafka Connect 以处理 10K S3 存储桶
- javascript - 我们可以在没有 npm 发布的情况下使用 github 标签作为 package.json 中的依赖项吗?
- reactjs - 以编程方式将输入传递给基于 Web 的终端
- flutter - 为什么我在启动时会收到错误消息:flutter pub get flutter pub run flutter_launcher_icons:main
- javascript - 如何使用 D3 树图中的节点使用 id 属性触发带有图像/媒体的鼠标悬停弹出窗口?
- typo3 - Typo3 工作区元素未在预览中显示