Ratio Full Screen Box
by Vladimir Kutepov
HTML
<div class="header"></div>
<div class="container">
<div class="box"></div>
<div class="bar"></div>
</div>
CSS
body {
margin: 0;
}
.box {
margin: 0 auto;
height: calc(100vh - 100px - 80px);
width: calc(177.78vh - 178px - 142px); /* 16/9 = 1.778 */
max-width: 100%;
max-height: 56.25vw; /* 100/1.778 = 56.25 */
min-height: 180px; /* 320 * 9/16 = 180 */
min-width: 320px;
background: yellow url(https://upload.wikimedia.org/wikipedia/en/b/be/Locator_Grid.png) no-repeat 50% 50%;
background-size: cover;
}
.bar {
background: orange;
height: 80px;
}
@media (min-width: 700px) {
.header {
height: 100px;
background: gray;
}
}
@media (max-width: 699px) {
.container {
height: 100vh;
display: flex;
flex-direction: column;
justify-content: center;
}
.box {
height: calc(100vh - 80px);
width: calc(177.78vh - 142px); /* 16/9 = 1.778 */
}
}