<section>
<div class="grid__container">
<div class="grid__item"> 16 / 9 </div>
<div class="grid__item"> 4 / 3 </div>
<div class="grid__item"> 2 / 1 </div>
</div>
<form action="">
<input type="range" min="0" max="100" value="100" />
</form>
</section>
<div class="select">
<label for="select">width:</label>
<select name="select" id="width">
<option value="auto">auto</option>
<option value="min-content">min-content</option>
<option value="max-content">max-content</option>
<option value="fit-content">fit-content</option>
<option value="50%">50%</option>
<option value="10em">10em</option>
<option value="300px">300px</option>
<option value="fit-content(200px)">fit-content(200px)</option>
<option value="min(100px, 20vh)">min(100px, 20vh)</option>
<option value="max(20vh, 200px)">max(20vh, 200px)</option>
<option value="clamp(100px, 30vh, 200px)">clamp(100px, 30vh, 200px)</option>
<option value="30ch">30ch</option>
<option value="30ex">30ex</option>
<option value="20vh">20vh</option>
<option value="10vw">10vw</option>
</select>
<label for="select">height:</label>
<select name="select" id="height">
<option value="auto">auto</option>
<option value="min-content">min-content</option>
<option value="max-content">max-content</option>
<option value="fit-content">fit-content</option>
<option value="50%">50%</option>
<option value="10em">10em</option>
<option value="300px">300px</option>
<option value="fit-content(200px)">fit-content(200px)</option>
<option value="min(100px, 20vh)">min(100px, 20vh)</option>
<option value="max(20vh, 200px)">max(20vh, 200px)</option>
<option value="clamp(100px, 30vh, 200px)">clamp(100px, 30vh, 200px)</option>
<option value="30ch">30ch</option>
<option value="30ex">30ex</option>
<option value="20vh">20vh</option>
<option value="10vw">10vw</option>
</select>
</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;
display: flex;
justify-content: center;
flex-direction: column;
gap: 20px;
font-family: "Exo", Arial, sans-serif;
background-color: #f7f7f7;
padding: 20px;
}
section {
margin: 0 auto;
display: flex;
flex-direction: column;
box-shadow: 0 0 0 6px rgb(0 0 0 / 13%);
border-radius: 3px;
gap: 20px;
min-width: 50vw;
}
.grid__item {
display: flex;
justify-content: center;
align-items: center;
background-color: #f7f7f7;
position: relative;
}
.grid__item:nth-child(1) {
background-color: #f1c2c6;
}
.grid__item:nth-child(2) {
background-color: #dac2f1;
}
.grid__item:nth-child(3) {
background-color: #ccf1c2;
}
.grid__item:nth-child(4) {
background-color: #f09;
}
.grid__item:nth-child(5) {
background-color: #09f;
}
.grid__item:nth-child(6) {
background-color: #90f;
}
form {
width: 100%;
}
input[type="range"] {
width: 100%;
}
.select {
display: flex;
justify-content: center;
align-items: center;
gap: 10px;
}
.grid__container {
box-shadow: 0 0 0 2px red;
border-radius: 2px;
display: grid;
grid-template-columns: repeat(3, 1fr);
--width: 100%;
width: var(--width);
}
.grid__item:nth-child(1) {
aspect-ratio: 16 / 9;
}
.grid__item:nth-child(2) {
aspect-ratio: 4 / 3;
}
.grid__item:nth-child(3) {
aspect-ratio: 2 / 1;
}
.grid__item {
height: var(--item-width, auto);
width: var(--item-height, auto);
}
const range = document.querySelector('input[type="range"]');
const container = document.querySelector(".grid__container");
const selects = document.querySelectorAll("select");
range.addEventListener("input", (etv) => {
container.style.setProperty("--width", `${etv.target.value}%`);
});
selects.forEach((select) => {
select.addEventListener("change", (etv) => {
container.style.setProperty(`--item-${etv.target.id}`, etv.target.value);
});
});
View Compiled
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.