我有这个代码

Html:

<div class="index-fifth">
  <div class="index-fifth-head">
    <h2>Why Us?</h2>
    <h1>Our Advantage</h1>
  </div>
  <div class="index-fifth-wrappers">
    <div class="index-fifth-wrapper-1">
      <div style="display: flex; gap: 1em; padding-top: 15px;">
        <i class="fa-solid fa-hospital"></i>
        <p>Credible</p>
      </div>
      <p style="margin-top: 40px;">The medical consultants present on MedConnect are confirmed and cross-checked to be official and credible when they sign up on MedConnect. Through the relevant medical details that they <br> provide, MedConnect affirms them to be credible consultants.</p>
    </div>
    <div class="index-fifth-wrapper-2">
      <div style="display: flex; gap: 1em; padding-top: 15px;">
        <i class="fa-solid fa-hospital"></i>
        <p>Credible</p>
      </div>
      <p style="margin-top: 40px;">The medical consultants present on MedConnect are confirmed and cross-checked to be official and credible when they sign up on MedConnect. Through the relevant medical details that they <br> provide, MedConnect affirms them to be credible consultants.</p>
    </div>
    <div class="index-fifth-wrapper-3">
      <div style="display: flex; gap: 1em; padding-top: 15px;">
        <i class="fa-solid fa-hospital"></i>
        <p>Credible</p>
      </div>
      <p style="margin-top: 40px;">The medical consultants present on MedConnect are confirmed and cross-checked to be official and credible when they sign up on MedConnect. Through the relevant medical details that they <br> provide, MedConnect affirms them to be credible consultants.</p>
    </div>
  </div>
</div>

Css:以下内容:

.index-fifth-head {
        display: flex;
        flex-direction: column;
        align-items: center;
        margin: 50px;
        gap: 1em;
        color: #704a1b;
      }

      .index-fifth-head h1 {
        color: #614124;
      }

      .index-fifth-wrappers {
        font-size: 17px;
        background-color: #ffdc84;
        padding: 20px;
        width: 450px;
        border-radius: 5px;
        color: #704a1b;
      }

现在,这些div如下所示(.index-fifth-wrappers不使用display: flex):

enter image description here

现在,当我使用display: flex并像这样修改代码时:

.index-fifth-wrappers {
        font-size: 17px;
        background-color: #ffdc84;
        padding: 20px;
        width: 450px;
        border-radius: 5px;
        color: #704a1b;
        display: flex;
        justify-content: space-around;
      }

这种情况会发生:

enter image description here

我怎么才能让它看起来像这样呢?

enter image description here

推荐答案

您需要将背景 colored颜色 移动到每个项目,然后将包装宽度设置为100%.将gap加到弹性物品上,然后给flex: 1物品,你就可以go 掉justify-content: space-between;了.

看看这个.我给每一件物品加了flex-item个班级.请随意为其重命名.

.index-fifth-head {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin: 50px;
  gap: 1em;
  color: #704a1b;
}

.index-fifth-head h1 {
  color: #614124;
}

.index-fifth-wrappers {
  padding: 20px;
  width: 450px;
  border-radius: 5px;
  color: #704a1b;
  display: flex;
  gap: 2rem;
  width: 100%;
}

.flex-item {
  background-color: #ffdc84;
  flex: 1;
  padding: 1rem;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}
<div class="index-fifth">
  <div class="index-fifth-head">
    <h2>Why Us?</h2>
    <h1>Our Advantage</h1>
  </div>
  <div class="index-fifth-wrappers">
    <div class="flex-item index-fifth-wrapper-1">
      <div style="display: flex; gap: 1em; padding-top: 15px;">
        <i class="fa-solid fa-hospital"></i>
        <p>Credible</p>
      </div>
      <p style="margin-top: 40px;">The medical consultants present on MedConnect are confirmed and cross-checked to be official and credible when they sign up on MedConnect. Through the relevant medical details that they <br> provide, MedConnect affirms them to be credible consultants.</p>
    </div>
    <div class="flex-item index-fifth-wrapper-2">
      <div style="display: flex; gap: 1em; padding-top: 15px;">
        <i class="fa-solid fa-hospital"></i>
        <p>Credible</p>
      </div>
      <p style="margin-top: 40px;">The medical consultants present on MedConnect are confirmed and cross-checked to be official and credible when they sign up on MedConnect. Through the relevant medical details that they <br> provide, MedConnect affirms them to be credible consultants.</p>
    </div>
    <div class="flex-item index-fifth-wrapper-3">
      <div style="display: flex; gap: 1em; padding-top: 15px;">
        <i class="fa-solid fa-hospital"></i>
        <p>Credible</p>
      </div>
      <p style="margin-top: 40px;">The medical consultants present on MedConnect are confirmed and cross-checked to be official and credible when they sign up on MedConnect. Through the relevant medical details that they <br> provide, MedConnect affirms them to be credible consultants.</p>
    </div>
  </div>
</div>

Html相关问答推荐

我似乎不能正确地将我的导航栏居中'

输入宽度在表格显示上不起作用FLEX溢出隐藏Firefox

防止SVG边框半径zoom

通过动态div的对角线

在FlexBox中将div拉伸到父div的完全高度

Bootstrap nav没有崩溃

Style=背景图像URL引用变成&;Quot;

带下划线的文本应该有延长的下划线,以使其图像悬停

浮动Div在CSS中未按预期工作

动画的停止和启动并不顺利

我的 *ngFor 中的 array.reverse() 在生产中不起作用

为什么我的 html 对话框在 React 中没有渲染在我的内容之上?

jQuery 索引返回不正确的结果

悬停时宽度从 0 过渡到自动

防止按钮溢出到新行

文本溢出:省略号不适用于 flexbox

在 jinja 模板内的 html 表中嵌套 For 循环

每次按下按钮时减小字体大小的 jquery 函数

是否可以设置用户在联系表单中输入的文本字体的样式

我的卡片内容无法在 bootstrap 5 中正确居中