<div class="parent">
<div class="aspectratio aspectratio__min" data-type="min(50%, 200px)">4:3</div>
</div>
<div class="parent">
<div class="aspectratio aspectratio__max" data-type="max(50%, 200px)">4:3</div>
</div>
<div class="parent">
<div class="aspectratio aspectratio__clamp" data-type="clamp(200px, 50%, 400px)">4:3</div>
</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: grid;
grid-template-columns: repeat(3, 1fr);
font-size: 1.5rem;
gap: 10px;
padding: 10px;
}
.parent {
font-size: 16px;
line-height: 1.5;
border: 1px dotted #f36;
padding: 4px;
position: relative;
}
.aspectratio {
aspect-ratio: 4 / 3;
background-color: #09f;
display: flex;
justify-content: center;
align-items: center;
}
.aspectratio__min {
width: min(50%, 200px);
}
.aspectratio__max {
width: max(50%, 200px);
}
.aspectratio__clamp {
width: clamp(200px, 50%, 400px);
}
.aspectratio::after {
content: "width:" attr(data-type);
position: absolute;
left: 0;
right: 0;
white-space: nowrap;
bottom: 5px;
text-align: center;
}
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.