first-child生效而last-child不生效
时间: 2023-10-27 09:06:07 浏览: 125
问题:first-child生效而last-child不生效的原因是什么?
回答: 这个问题出现的原因是CSS选择器中的last-child选择器的生效条件是父元素的最后一个子元素必须是特定的元素,而不是仅仅是父元素的最后一个子元素。在给定的HTML结构中,最后一个子元素是loading而不是c1,所以last-child选择器没有匹配到任何元素,导致样式不生效。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* [解决css样式中first-child和last-child不生效的问题](https://blog.csdn.net/weixin_44684272/article/details/121583249)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"]
- *2* *3* [last-child不生效问题](https://blog.csdn.net/HYeeee/article/details/119797997)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文