Flex-box: Align last row to grid

后端 未结 29 2494
不知归路
不知归路 2020-11-22 02:54

I have a simple flex-box layout with a container like:

.grid {
  display: flex;
  flex-flow: row wrap;
  justify-content: space-between;
}

29条回答
  •  [愿得一人]
    2020-11-22 03:06

    Yes.! We can but with some media queries & Maximum no of columns are predefined.

    Here am using 4 columns. Check my code:

    .container {
      display: flex;
      display: -webkit-flex;
      display: -moz-flex;
      flex-flow: row wrap;
      -webkit-flex-flow: row wrap;
      -moz-flex-flow: row wrap;
    }
    
    .container .item {
      display: flex;
      display: -webkit-flex;
      display: -moz-flex;
      justify-content: center;
      -webkit-justify-content: center;
      -moz-justify-content: center;
      flex-basis: 25%; //max no of columns in %, 25% = 4 Columns
    }
    
    .container .item .item-child {
      width: 130px;
      height: 180px;
      background: red;
      margin: 10px;
    }
    
    @media (max-width: 360px) {
      .container .item {
        flex-basis: 100%;
      }
    }
    
    @media (min-width:360px) and (max-width: 520px) {
      .container .item {
        flex-basis: 50%;
      }
    }
    
    @media (min-width:520px) and (max-width: 680px) {
      .container .item {
        flex-basis: 33.33%;
      }
    }
    1

    NOTE
    1) No need to create child div. It may be any other tag like 'img' r whatever you want..
    2) If you want more columns adjust the media queries and maximum no.of columns.

提交回复
热议问题