html - 包含文本和图像时的 Flexbox 格式问题

标签 html css

我正在尝试使用 Flexbox 创建看起来像这样的东西,但我遇到了困难。见图片示例:

enter image description here

我尝试过使用 float 来做这件事,但我认为这太具有挑战性了。所以我正在玩 flexbox。

我还使用我的 css 来传递图像。

.flex-container {
  display: flex;
  justify-content: center;
  background-color: DodgerBlue;
}

.flex-container>div {
  border: 1px solid #fff;
  width: 300px;
  justify-content: space-around;
  background-color: #f1f1f1;
  margin: 10px;
  padding: 20px;
  font-size: 30px;
}

.row {
  display: flex;
  justify-content: center;
}

.row_cell {
  flex: 1
}

.phoneimg {
  display: flex;
  background-image: url(%image(MS_HR_MR_PHONE_FL));
  background-repeat: no-repeat;
  content: "";
  background-color: rgba(255, 255, 255, 0.0);
  background-size: 55px 90px;
  */ width: 55px;
  height: 90px;
}
<div class="flex-container">
  <div>
    <div class="phoneimg">
      <div>column1</div>
    </div>
  </div>
  <div>
    <div class="phoneimg">
      <div>column2</div>
    </div>
  </div>
  <div>
    <div class="phoneimg">
      <div>column3</div>
    </div>
  </div>
  <div class="row">
    <div class="rowcell">row</div>
  </div>
</div>

我期待看到列,但所有内容都是垂直堆叠的。

最佳答案

您可以通过 flex 的分层方法实现这一点。首先在两行的列方向使用 flex,然后在第一行,您可以按照您的方式在行方向使用 flex。

<!doctype html>
<html>

<head>
  <meta charset="UTF-8">
  <title>Untitled Document</title>
  <style>
    .parent-container {
      background-color: DodgerBlue;
      display: flex;
      flex-direction: column;
      justify-content: center;
    }
    
    .flex-container {
      display: flex;
      justify-content: center;
    }
    
    .flex-container>div {
      border: 1px solid #fff;
      width: 300px;
      justify-content: space-around;
      background-color: #f1f1f1;
      margin: 10px;
      padding: 20px;
      font-size: 30px;
    }
    
    .row {
      display: flex;
      justify-content: center;
      border: 1px solid #fff;
      background-color: #f1f1f1;
      margin: 10px;
      padding: 20px;
      font-size: 30px;
    }
    
    .row_cell {
      flex: 1
    }
    
    .phoneimg {
      display: flex;
      background-image: url(%image(MS_HR_MR_PHONE_FL));
      background-repeat: no-repeat;
      content: "";
      background-color: rgba(255, 255, 255, 0.0);
      background-size: 55px 90px;
      */ width: 55px;
      height: 90px;
    }
  </style>
</head>

<body>
  <div class="parent-container">
    <div class="flex-container">
      <div>
        <div class="phoneimg">
          <div>column1</div>
        </div>
      </div>
      <div>
        <div class="phoneimg">
          <div>column2</div>
        </div>
      </div>
      <div>
        <div class="phoneimg">
          <div>column3</div>
        </div>
      </div>
    </div>
    <div class="row">
      <div class="rowcell">row</div>
    </div>
  </div>
</body>

</html>

关于html - 包含文本和图像时的 Flexbox 格式问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56437350/

相关文章:

html - 无法使用 CSS 设置复选框样式?

javascript - 如何防止div滚出页面

css - 编译后登录表单出现奇怪的边框

html - 通过用 css 悬停另一个 div 来显示一个用表单 Action 包裹的 div

html - 固定位置 Action 响应

html - 如何使白色div中的TEXT完全透明以显示背景?

javascript - 可折叠的 div block 嵌套在另一个 block 中以重新调整整个 block 的最大高度

html - 这是一个 IE 错误吗? `body.foo.bar .container` 被应用于每个 body 元素

html - 使用 HTML/CSS 的水平线

html - 无法在溢出时将滚动条附加到我的 div