html - Why :last-of-type does not work if there is another element at the end of the parent?
问题描述
Someone tell me, please, why can not I get the last item with text "STYLE ME" in the first case? I would like to receive a detailed explanation and I would not want to create extra wrappers as I did in my alternative version. Thanks.
.section > .block:last-of-type {
border: 1px solid black;
}
/* Working alternative */
.block-wrap > .block:last-of-type {
border: 1px solid black;
}
<b>Does not work:</b>
<div class="section">
<div class="block">one</div>
<div class="block">too</div>
<div class="block">
three
<div class="block">nested (ignore me)</div>
</div>
<div class="block">STYLE ME</div>
<div class="line">{Line}</div>
</div>
<hr>
<b>If you delete .line, it works:</b>
<div class="section">
<div class="block">one</div>
<div class="block">too</div>
<div class="block">
three
<div class="block">nested (ignore me)</div>
</div>
<div class="block">STYLE ME</div>
</div>
<hr>
<b>Working alternative:</b>
<div class="section">
<div class="block-wrap">
<div class="block">one</div>
<div class="block">too</div>
<div class="block">
three
<div class="block">nested (ignore me)</div>
</div>
<div class="block">STYLE ME</div>
</div>
<div class="line">{Line}</div>
</div>
解决方案
推荐阅读
- google-apps-script - 无法在 Google Apps 脚本插件的“授予权限”对话框中设置项目名称
- c++ - 双三次插值 - 时间与规模
- javascript - 从 wordpress 前端删除图像
- javascript - 如何制作悬停效果而不是单击引导程序 4 下拉菜单?
- php - 加入同一张表,忽略空值
- python - 如何从pdf文件中提取特定文本 - python
- django - 返回 user_id 作为 post api 的响应
- three.js - three.js 中的坐标系问题
- java - 拆分和乘以 double 会给我错误的值
- php - 如何替换主题标签后跟数字?