Reputation: 396
I have found an example on Codepen which splits the screen in two halves.
How to make the example divide the screen vertically when the height is smaller than the width? I want to utilize the screen area on small devices better, because in my opinion a narrow long rectangle looks worse than a nearly square rectangle.
.leftside, .rightside {
height:50vh;
width:100%;
color:#fff;
font-size:40px;
}
@media screen and (min-width:768px)
{
.leftside, .rightside {
height:100vh;
}
}
Upvotes: 1
Views: 567
Reputation: 2548
You can do this with aspect-ratio -> 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>
Upvotes: 2