<div class="container"></div>
<div class="control">
<button class="button">Add Item</button>
<input type="checkbox" id="contain">
<label for="contain">contain: size</label>
</div>
@import url("https://fonts.googleapis.com/css2?family=Exo:wght@600&display=swap");
* {
box-sizing: border-box;
}
body {
width: 100vw;
min-height: 100vh;
display: flex;
flex-direction: column;
align-items: center;
padding: 5vh;
font-family: "Exo", Arial, sans-serif;
font-size: 20px;
font-weight: 600;
}
.container {
border: 1px dashed #f36;
padding: 5px;
margin-top: auto;
counter-reset: item;
display: flex;
flex-wrap: wrap;
gap: 5px;
align-content: flex-end;
}
button {
margin-top: 40px;
border-radius: 6px;
background-color: transparent;
border: 4px solid #3f3d56;
padding: 10px 20px;
outline: none;
color: #3f3d56;
cursor: pointer;
font-family: "Exo", Arial, sans-serif;
font-size: 20px;
font-weight: 600;
}
button:active {
color: #6c63ff;
border-color: #6c63ff;
transform: rotate(0.1deg) scale(0.9);
transform-origin: 50% 100%;
}
.box {
height: 50px;
width: 50px;
display: flex;
justify-content: center;
align-items: center;
background-color: #09f;
border-radius: 4px;
gap: 5px;
flex-shrink: 0;
}
.box::before {
counter-increment: item;
content: counter(item);
color: #fff;
}
.size {
contain: size;
}
View Compiled
const containEle = document.querySelector(".container");
const buttonEle = document.querySelector(".button");
const checkboxEle = document.querySelector("#contain");
buttonEle.addEventListener("click", () => {
const box = document.createElement("div");
box.classList.add("box");
containEle.append(box);
});
checkboxEle.addEventListener("change", (etv) => {
containEle.classList.toggle("size", etv.target.checked);
});
View Compiled
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.