【发布时间】:2021-04-19 10:44:21
【问题描述】:
我正在处理与此示例类似的卡片列表: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>
但是在完成它之后,我无法摆脱纯粹使用 CSS 可以实现的感觉,我只是想不出如何以不同的方式实现它。有什么建议吗?
【问题讨论】:
标签: css