【发布时间】:2019-11-06 20:14:49
【问题描述】:
我正在尝试更改最后一个 div 的颜色。 last-child 和 last-of-type 都不起作用。我的代码:
.blue-back {
background-color:blue;
}
.blue-back:last-of-type {
background-color:red;
}
.blue-back:last-child {
background-color:red;
}
<div class="row">
<div class="col-md-4">
<div class="blue-back">
<p class="mb-0 text-center text-white">Fase</p>
<p style="font-size:29px; font-weight:600;" class="mb-0 text-center text-white font-weight-600">1</p>
</div>
</div>
<div class="col-md-4">
<div class="blue-back">
<p class="mb-0 text-center text-white">Fase</p>
<p style="font-size:29px; font-weight:600;" class="mb-0 text-center text-white font-weight-600">1</p>
</div>
</div>
<div class="col-md-4">
<div class="blue-back">
<p class="mb-0 text-center text-white">Fase</p>
<p style="font-size:29px; font-weight:600;" class="mb-0 text-center text-white font-weight-600">1</p>
</div>
</div>
</div>
【问题讨论】:
-
您只需要确保父母中确实有孩子。在这种情况下,每个项目只有一个名为 .blue-black 的 last-child
标签: html css css-selectors