5 items per row, auto-resize items in flexbox

后端 未结 4 1601

I have this at the moment:

4条回答
  •  清歌不尽
    2020-11-27 18:43

    I'm using this on a WordPress project, where I have to list articles by categories, nested in columns. I just wrote some css for the responsive layout, so as you decrease the browser width, there are less elements in a row.

    .container {
      margin: 20px auto;
      width: 80%;
      min-height: 100px;
      display: flex;
      flex-flow: row wrap;
    }
    
    .item {
      margin: 10px;
      flex: 1 1 calc(20% - 20px);
      background-color: lightgreen;
    }
    
    @media screen and (max-width: 1200px) {
      .item {
        flex: 1 1 calc(25% - 20px)
      }
    }
    
    @media screen and (max-width: 900px) {
      .item {
        flex: 1 1 calc(33% - 20px)
      }
    }
    
    @media screen and (max-width: 750px) {
      .item {
        flex: 1 1 calc(50% - 20px)
      }
    }
    
    @media screen and (max-width: 550px) {
      .item {
        flex: 1 1 calc(100% - 20px)
      }
    }

提交回复
热议问题