2018年2月15日 星期四

【Flex】自動分配各自平行的子元素的垂直位置,align-items


<!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>Document</title>
  <style>
    *{
      margin: 0;
      padding: 0;
    }
    .wrapper{
      display:flex;
      height:200px;
      width: 200px;
      margin: 20px;
      border:1px solid #ddd;
      align-items: stretch;
      /*stretch*/
      /*center*/
      /*flex-start*/
      /*flex-end*/
      /*baseline*/
    }
    .box{
      width: 50px;
      height:50px;
    }
    .box:nth-child(3n){
      background-color: #f00;
    }
    .box:nth-child(3n+1){
      background-color: #0f0;
      height:100px;
    }
    .box:nth-child(3n+2){
      background-color: #00f;
      height:20px;
    }
  </style>
</head>
<body>
  <div class="wrapper">
    <div class="box"></div>
    <div class="box"></div>
    <div class="box"></div>
    <div class="box"></div>
    <div class="box"></div>
  </div>
</body>
</html>

See the Pen WMXZrg by Jerry (@fenture) on CodePen.

沒有留言:

張貼留言