当前位置:网站首页>last-child不生效问题
last-child不生效问题
2022-07-23 05:39:00 【一条大河全靠浪】
写css的时候碰到一个神奇的问题,first-child生效、但last-child失效。
观察样式和代码结构如下:
<div class="c0">
<div class="c1"></div>
<div class="c1"></div>
<div class="loading"></div>
</div>
.c0 .c1:last-child {
padding: 10px;
}
原因是,.c0 .c1:first-child , 这个选择器发现c0下第一个确实是c1,匹配到了第一行,生效。.c0 .c1:last-child,这个选择器的生效条件其实是c0最后一个子元素必须是c1,但实际HTML结构中,最后一个是loading,所以没生效。
解决办法有2个:
1、保证c0是新嵌套div的最后一个元素。但很难做到,实际情况总会各种类型元素夹杂穿插在一起。
2、使用.c0 .c1:last-of-type
边栏推荐
- The attribution of branch and loop statements in C language
- 【无标题】
- Web server failed to start. Port 8080 was already in use.
- JWT header进行编码过程
- NPM init vite app < project name > error install for[‘ [email protected] ‘] failed with code 1
- Inheritance mode of JS
- JDBC database connection pool
- Keras保存训练过程中的最好模型
- 【无标题】
- C语言中的分支和循环语句归属
猜你喜欢
D2DEngine食用教程(1)———最简单的程序

Clear the buffer with getchar (strongly recommended, C language is error prone, typical)

自定义公式输入框

Fun code rain, share it online~-

牛客刷题记录--Mysql

PyGame realizes the airplane war game

Error when PLSQL creates Oracle Database: when using database control to configure the database, it is required to configure the listener in the current Oracle home directory. You must run netca to co

Cell sends SMS asynchronously

C语言调试常见错误——简答

从零开始的pytorch小白使用指北
随机推荐
知识点回顾
How to merge the website content with video and audio separated? How to write batch download code?
通用视图,序列化器
JS higher order function
JDBC database connection pool
py程序可以运行,但打包出的exe运行提示错误:加载“cv2”二进制扩展时检测到递归。请检查OpenCV安装。
C语言中的流氓goto语句
cuda10.0配置pytorch1.7.0+monai0.9.0
Anti shake and throttling of JS
pyspark学习笔记
Pytorch white from zero uses North pointing
【无标题】
$attrs中的对象没有变化,但触发了watch监听?
[Hudi]hudi的编译及hudi&spark和hudi&flink的简单使用
Copy a project /project in idea
Sorting out common SQL interview questions and answers
自定义公式输入框
【无标题】
忽略埋点记录的ResizeObserver - loop limit exceeded
Understanding of closures of JS