【问题标题】:align-self property in flexbox is not workingflexbox 中的 align-self 属性不起作用
【发布时间】:2020-03-22 23:54:51
【问题描述】:

我想让 item-2 居中,我无法让 align-self 工作。 请问我做错了什么?我已经尝试了 align-self 的所有选项,但它似乎没有注册。

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Flex Align</title>
  <style>
    #container {
      background: #555 ;
      display: flex;
      flex-wrap: wrap;
      justify-content: space-evenly;
      height: 600px;
      align-items: baseline;
      align-content: space-between;
    }

    .item-2 {
      align-self: center;
    }  
    
    .item {
      background: #f4f4f4;
      border: #ccc solid 1px;
      padding: 1rem;
      text-align: center;
      margin: 0.5rem;
      flex-basis: 200px;
  }
  </style>
</head>
<body>
  <div id="container">
    <div class="item item-1"><h3>Item 1</h3></div>
    <div class="item item-2"><h3>Item 2</h3></div>
    <div class="item item-3"><h3>Item 3</h3></div>
  </div>
</body>
</html>

【问题讨论】:

标签: css flexbox alignment


【解决方案1】:

如果您从容器中删除 align-content: space-between 并为 .item 添加高度,则您将能够选择单个项目并 align-self: center 将该项目垂直设置在中间。

【讨论】:

    猜你喜欢
    • 2013-12-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-03-19
    • 2017-05-14
    • 2013-05-21
    • 2017-12-06
    相关资源
    最近更新 更多