I'm working on a list of cards similar to this example: https://codepen.io/pkunzel/pen/xxgjrVg
window.addEventListener("load", function() {
let cards = document.querySelectorAll(".card");
for (let i = 0; i < cards.length; i++) {
cards[i].style.marginTop = (i * 30) + "px";
}
});
.card {
position: absolute;
}
.blue {
background-color: cornflowerblue;
}
.green {
background-color: darkolivegreen;
}
.red {
background-color: lightcoral;
}
.orange {
background-color: lightsalmon;
}
<div class="card-group">
<div class="card blue">
<p>Name: qwert</p>
<p>Age: 99</p>
<p>Address: qwertyuil</p>
</div>
<div class="card red">
<p>Name: qwert</p>
<p>Age: 99</p>
<p>Address: qwertyuil</p>
</div>
<div class="card green">
<p>Name: qwert</p>
<p>Age: 99</p>
<p>Address: qwertyuil</p>
</div>
<div class="card orange">
<p>Name: qwert</p>
<p>Age: 99</p>
<p>Address: qwertyuil</p>
</div>
</div>
But after completing it I can't shake off the feeling it could purely with CSS, I just can't figure out how to implement it differently. Any suggestions?