子元素在flex容器中不可见

时间:2016-08-01 01:13:00

标签: html css flexbox

我已将div输入容器{display:flex}。一旦我摆脱显示:flex它工作正常,我可以看到我的HTML。另外我发现如果我将百分比更改为px,我可以查看我的页面。

为什么会这样?

* {
  padding: 0;
  margin: 0;
  box-sizing: border-box;
  margin-top: .2%;
}
#container {
  display: flex;
  flex-flow: row wrap;
}
#one {
  float: left;
  background-color: black;
  width: 25%;
  height: 100vh;
  margin-left: 2%;
}
#two {
  float: right;
  background-color: grey;
  width: 70.5%;
  height: 100vh;
  margin-right: 2%;
}
<div id="container">
  <div id="row">
    <div id="one"></div>
    <div id="two"></div>
  </div>
</div>

1 个答案:

答案 0 :(得分:2)

&#13;
&#13;
html, body{ height:100%;} /* not needed but good to have it */

* {
  padding: 0;
  margin: 0;
  box-sizing: border-box;
  /*margin-top: .2%; /* why? it'll mess with vh100 adding scrollbars.. */
}
/*#container { you mean... */
#row {
  display: flex;
  flex-flow: row wrap;
}
#one {
  /* float: left; /* unnecessary, now parent is flex */
  background-color: black;
  width: 25%;
  height: 100vh;
  margin-left: 2%;
}
#two {
  /* float: right; /* unnecessary, now parent is flex */
  background-color: grey;
  width: /*70.5%; you mean... */ 71%;
  height: 100vh;
  margin-right: 2%;
}
&#13;
<div id="container">
  <div id="row">
    <div id="one"></div>
    <div id="two"></div>
  </div>
</div>
&#13;
&#13;
&#13;