【问题标题】:struggling with a nested flexbox grid与嵌套的 flexbox 网格作斗争
【发布时间】:2017-07-10 06:39:17
【问题描述】:

我尝试使用基于负边距的网格系统 (susy) 实现类似网格的模式,但失败了。

我尝试使用 flexbox,但我不确定它是否真的可行,我认为最好的方法是 2 列(A 侧和 B 侧)并为框 (1) 提供 50% 的框 2 的 flex 高度,但它似乎不起作用。

据我所知,这是可行的。

.block {
  width: 100%;
  background: grey
}

.column {
    align-content: stretch;
    display: flex;
    flex-flow: column wrap;
    width: 50%;
}

.box_long {
  background-color: pink;
  flex: 0 0 50%;
  padding: 20px;
  border: solid 1px black;
}

.box_small {
  background-color: blue;
  flex: 0 0 25%;
  padding: 20px;
  border: solid 1px black;
}

.box_big {
  background-color: green;
  flex: 0 0 100%;
  padding: 20px;
  border: solid 1px black;
}
<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>

【问题讨论】:

    标签: html css flexbox susy-sass


    【解决方案1】:

    这是你要找的吗?

    * {
      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>

    【讨论】:

    • 几乎,。非常感谢,粉红色应该有蓝色的高度,但我会用 flex 解决这个问题或使用固定值我猜...非常感谢
    【解决方案2】:

    这是一种可能适合您的方法:

    (不更改 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

    【讨论】:

    • 那是个好主意,我会尝试这两个答案,并在我知道哪种方法最有效时尽快回来......非常感谢大家
    猜你喜欢
    • 2015-03-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-23
    • 1970-01-01
    • 2011-12-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多