<div class="aspectratio aspectratio__wh">
4 : 3
<span class="width">width: 30vw</span>
<span class="height">height: 30vh</span>
</div>
<div class="aspectratio aspectratio__h">
4 : 3
<span class="width">width: auto</span>
<span class="height">height: 30vh</span>
</div>
<div class="aspectratio aspectratio__w">
4 : 3
<span class="width">width: 30vw</span>
<span class="height">height: auto</span>
</div>
@import url("https://fonts.googleapis.com/css2?family=Exo:wght@600&display=swap");
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
width: 100vw;
min-height: 100vh;
font-family: "Exo", Arial, sans-serif;
background-color: #222;
color: #fff;
display: flex;
align-items: center;
justify-content: center;
font-size: 1.5rem;
gap: 50px;
}
.aspectratio {
background-color: #09f;
display: flex;
justify-content: center;
align-items: center;
position: relative;
}
.aspectratio span {
position: absolute;
white-space: nowrap;
}
.width {
left: 5px;
right: 5px;
bottom: calc(100% + 5px);
text-align: center;
}
.height {
top: 5px;
bottom: 5px;
writing-mode: vertical-lr;
text-align: center;
left: calc(100% + 5px);
}
.aspectratio {
aspect-ratio: 4 / 3;
}
.aspectratio__wh {
width: 30vw;
height: 30vh;
}
.aspectratio__h {
height: 30vh;
}
.aspectratio__w {
width: 30vw;
}
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.