struggling with a nested flexbox grid

后端 未结 2 1675
谎友^
谎友^ 2021-01-19 18:57

i tried to achieve a grid like pattern with a negative margin based grid system (susy) and failed.

I tried to use flexbox, but i am not sure if its really possible,

相关标签:
2条回答
  • 2021-01-19 19:29

    Here's one method that may work for you:

    (No changes to the HTML.)

    .block {
      display: flex;
      height: 100vh;
      background: grey;
    }
    
    .column {
      display: flex;
      flex-wrap: wrap;
      width: 50%;
    }
    
    .box_big {
      flex-basis: 100%;
      height: 70%;
      background-color: chartreuse;
      border: solid 1px black;
    }
    
    .box_small {
      flex: 0 0 50%;
      height: 35%;
      background-color: aqua;
      border: solid 1px black;
    }
    
    .box_long {
      flex-basis: 100%;
      height: 30%;
      background-color: violet;
      border: solid 1px black;
    }
    
    * {
      margin: 0;
      box-sizing: border-box;
    }
    <div class="block">
      <div class="column">
        <div class="box_long"></div>
        <div class="box_big"></div>
      </div>
      <div class="column">
        <div class="box_small"></div>
        <div class="box_small"></div>
        <div class="box_small"></div>
        <div class="box_small"></div>
        <div class="box_long"></div>
      </div>
    </div>

    jsFiddle

    0 讨论(0)
  • 2021-01-19 19:30

    Is this what you looking for?

    * {
      box-sizing: border-box
    }
    
    .block {
      background: grey;
      display: flex;
      height: 250px;
    }
    
    .column {
      flex: 1;
      display: flex;
      flex-wrap: wrap;
    }
    
    .column.col {
      flex-direction: column;
      flex-wrap: nowrap;
    }
    
    .column.col div {
      flex: 1;
      border: 1px solid black;
    }
    
    .column.row div {
      border: 1px solid black;
      flex-basis: 50%;
      height: 25%;
    }
    
    .column.row .box_long {
      height: 50%;
      flex-basis: 100%;
    }
    
    .box_long {
      background-color: pink;
    }
    
    .box_small {
      background-color: blue;
    }
    
    .box_big {
      background-color: green;
    }
    <div class="block">
    
      <div class="column col">
        <div class="box_long">
        </div>
        <div class="box_big">
        </div>
      </div>
    
      <div class="column row">
        <div class="box_small">
        </div>
        <div class="box_small">
        </div>
        <div class="box_small">
        </div>
        <div class="box_small">
        </div>
        <div class="box_long">
        </div>
      </div>
    
    </div>

    0 讨论(0)
提交回复
热议问题