flexbox父盒子align-items屬性

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <title>Document</title>
  <style>
  .flex-container {
    display: flex;
    /*總體上對齊*/
    /*align-items: flex-start;*/
    
    /*總體垂直居中*/
    /*align-items: center;*/

    /*總體下對齊*/
    /*align-items: flex-end;*/
    
    /*默認值:當子盒子沒有設置高度時,子盒子高度拉伸至和父盒子同高*/
    /*align-items: stretch;*/
    
    /*當文字大小不一時,子盒子以較大文字的基線對齊,不經常使用*/
    align-items: baseline;
    width: 400px;
    height: 400px;
    background-color: gray;
  }

  .flex-item {
    background-color: green;
    width: 100px;
    height: 100px;
    margin: 5px;
  }
  .flex-item:nth-child(1) {
    font-size: 20px;
  }

  .flex-item:nth-child(2) {
    font-size: 30px;
  }
  </style>
</head>

<body>
  <div class="flex-container">
    <div class="flex-item">flex item 1</div>
    <div class="flex-item">flex item 2</div>
    <div class="flex-item">flex item 3</div>
  </div>
</body>

</html>

相關文章
相關標籤/搜索