Flexbox-在小屏幕上拆分屏幕

时间:2019-01-30 06:21:18

标签: css twitter-bootstrap flexbox

我在Codepen上发现了example,可将屏幕分成两半。

当高度小于宽度时,如何使示例垂直分割屏幕?我想在小型设备上更好地利用屏幕区域,因为在我看来,窄长矩形看起来比近矩形更差。

.leftside, .rightside {
height:50vh;
width:100%;
color:#fff;
font-size:40px;
}

@media screen and (min-width:768px)
{
.leftside, .rightside {
    height:100vh;
}
}

horizontal

1 个答案:

答案 0 :(得分:1)

您可以使用纵横比-> https://developer.mozilla.org/en-US/docs/Web/CSS/@media/aspect-ratio

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
}

.container {
  display: flex;
  border: 5px solid green;
  flex-flow: row nowrap;
  height: 100%;
}

.container>div {
  flex: 1;
  height: 100vh;
  color: white;
  font-size: 40px;
}

.container>.leftside {
  background: red;
}

.container>.rightside {
  background: blue;
}

@media (min-aspect-ratio: 9/8) {
  .container {
    display: flex;
    border: 5px solid yellow;
    flex-flow: column nowrap;
  }
  .container>div {
    height: 50vh;
  }
}
<div class="container">
  <div class="leftside">left</div>
  <div class="rightside">right</div>
</div>