美文网首页
:last-child选择器不起作用

:last-child选择器不起作用

作者: 缘之空_bb11 | 来源:发表于2024-05-27 17:31 被阅读0次

1. 同级唯一, :last-child生效:

<view class="">
    <view class="cell" v-for="(item,index) in 5">你好,我有一个帽衫</view>
</view>

// 设置 Css
.cell:last-child {
    background: pink;
}

WechatIMG341.jpg

2. 同级多个且不是最后一个, :last-child失效 :

<view class="">
      <view class="cell" v-for="(item,index) in 5">你好,我有一个帽衫</view>
      <view class="">我是毛衣,不是帽衫</view>
</view>

// 设置 Css
.cell:last-child {
    background: pink;
}

WechatIMG342.jpg

3. 同级多个且是最后一个, :last-child生效 :

<view class="">
      <view class="">我是毛衣,不是帽衫</view>
      <view class="cell" v-for="(item,index) in 5">你好,我有一个帽衫</view>
</view>

// 设置 Css
.cell:last-child {
    background: pink;
}

WechatIMG343.jpg

通过上面的案例可得, 设置 :last-child 的时候,该控件必须在同级别中最后一个或唯一一个时,才会生效.

相关文章

  • :last-child选择器不起作用

    我们在开发的时候,想要为最后一个元素设置一些特殊的操作,css默认为我们提供了:last-child选择器,但是在...

  • :first-child以及:last-child易错点

    前言 对选择器理解的不够深入,今天说说以下几个选择器::first-child, :last-child, :fi...

  • CSS笔记15:结构伪类CSS3

    CSS3 first-child/last-child nth-child CSS3 伪元素选择器 :first-...

  • first-child、last-child

    很多人对last-child和first-child选择器有着很深的误会,以为匹配的是“所有符合匹配规则(:之前)...

  • CSS3-新增选择器

    属性选择器 结构伪类选择器 UI伪类选择器 UI伪类选择器只有当元素处于某种状态时才起作用,在默认状态下不起作用.

  • web前端面试题目--css篇(2019年实战整理)

    css篇 一、css3的新特性(不列全部,捡重点回答) 1、CSS3选择器:last-child、nth-chil...

  • C3新增伪类选择器之 last-child 和 last-of-

    last-child, last-of-type是CSS3新增的结构伪类选择器,这两者功能相似,如果不仔细区分,可...

  • 2019-05-28

    其他子元素选择器 :first-child 选择第一个子标签 :last-child 选择最后一个子标签 :nth...

  • CSS选择器

    1.后代选择器 后代选择器就是用来创建一些规则,它们仅在某些结构起作用,而在另外一些结构中不起作用。比如,希望只对...

  • css 应用总结

    css伪类 下面是自己使用过 伪类的几种场景 :last-child 利用 css:last-child,实现循环...

网友评论

      本文标题::last-child选择器不起作用

      本文链接:https://www.haomeiwen.com/subject/sjzcqjtx.html