【问题标题】:why doesn't my flex-row work on my inner div为什么我的 flex-row 不能在我的内部 div 上工作
【发布时间】:2021-10-16 23:51:57
【问题描述】:

我目前正在尝试将两个 div 水平相邻放置,我的想法是利用 flexbox,但添加属性 flex-row 似乎没有任何作用,我不知道为什么.

如何正确地将包含“Test”的 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>

此外,与 JSFiddle 相比,当我在本地运行它时,它看起来有所不同

【问题讨论】:

    标签: html css tailwind-css


    【解决方案1】:

    您只需在父容器中为类flex 更改类flex-row。请参阅下面的工作 sn-p:

    .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>

    【讨论】:

    • 哦!为什么 flex-row 不起作用?
    • 因为这个类做了别的事情。看看这里tailwind.build/classes/flex/flex-row - 如果解决了您的问题,请将其标记为正确答案:)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-02-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多