【问题标题】:How am I going to make this CSS我将如何制作这个 CSS
【发布时间】:2023-02-01 19:28:01
【问题描述】:

我要怎么转

变成

我尝试使用 justify-content: space between; 并将块分开,但我如何将 3 和 4 对齐到容器底部

CSS代码

.container {
  width: 240px;
  height: 200px;
  border: 1px solid gray;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
}

.container > div {
  width: 80px;
  height: 50px;
  border: 1px solid red;
}

【问题讨论】:

    标签: html css flexbox


    【解决方案1】:

    假设所有这些尺寸都是硬编码的,你可以这样做。

    * {
      box-sizing: border-box;
    }
    
    .container {
      width: 240px;
      height: 200px;
      border: 1px solid gray;
      display: flex;
      flex-wrap: wrap;
      justify-content: space-between;
      align-content: space-between;
    }
    
    .container > div {
      width: 80px;
      height: 50px;
      border: 1px solid red;
      flex-shrink: 0;
    }
    
    .container > div:nth-child(1),
    .container > div:nth-child(2),
    .container > div:nth-child(5) {
      order: -1;
    }
    
    .container > div:nth-child(5) {
      margin-inline: 80px;
    }
    <div class="container">
      <div>1</div>
      <div>2</div>
      <div>3</div>
      <div>4</div>
      <div>5</div>
    </div>

    【讨论】:

    • 怎么把文字放在方框的中央,我用text-align: center把数字放在方框的中间,但是竖着改不了。
    • @henryChan 查看 flexbox,它将满足您的需要。
    【解决方案2】:

    如果您的内部盒子的大小是固定的,您可以使用此解决方案。

    .parent {
      display: flex;
      justify-content: space-between;
      width: 100%;
      height: 80vh;
      border: 1px solid black;
      position: relative;
      resize: both;
    }
    
    div {
      display: inline-block;
      width: 100px;
      height: 30px;
      border: 1px solid red;
    }
    
    .three {
      position: absolute;
      bottom: 0%;
    }
    
    .four {
      position: absolute;
      bottom: 0%;
      right: 0%;
    }
    
    .five {
      position: absolute;
      bottom: 50%;
      right: 50%;
      transform: translate(50%, 50%);
    }
    <div class="parent">
      <div class="one">1</div>
      <div class="two">2</div>
      <div class="three">3</div>
      <div class="four">4</div>
      <div class="five">5</div>
    </div>

    【讨论】:

      猜你喜欢
      • 2018-09-21
      • 2015-02-22
      • 2021-05-05
      • 2021-10-20
      • 1970-01-01
      • 2017-01-17
      • 1970-01-01
      • 1970-01-01
      • 2022-01-16
      相关资源
      最近更新 更多