li:first-child{color:red} 2. last-child 选择列表中的最后一个标签 li:last-child{color:pink} 3.nth-child(n) 这里的n为数字,表示选择列表中的第n个标签 例如选择第三个标签 li:nth-child(3){color:pink} 4.nth-child(2n) 选择列表中的偶数,选中 2、4、6…… 个标签。 li:nth-child(2n){colo...
百度试题 题目CSS3中,:first-child选择器和:last-child选择器分别用于为父元素中的第一个或者【】子元素设置样式。相关知识点: 试题来源: 解析 最后一个 反馈 收藏
1、first-child first-child表示选择列表中的第一个标签。代码如下: li:first-child{background:#090} 上面的意思是,li 列表中的 第一个li模块的背景颜色。 2、last-child last-child表示选择列表中的最后一个标签,代码如下: li:last-child{background:#090} 3、nth-child(3) 表示选择列表中的第3个标签,...
first-child 和last-child是伪类选择器,选择第一个和选择最后一个子元素 现在实现下面的效果 代码语言:javascript 复制 代码语言:javascript 复制 .menuico span{display:block;width:21px;height:2px;background-color:#666;}.menuico span:first-child{margin-top:-6px;}.menuico span:last-child{margin-to...
1、first-child first-child表示选择列表中的第一个标签。代码如下: li:first-child{background:#090} 上面的意思是,li 列表中的 第一个li模块的背景颜色。 2、last-child last-child表示选择列表中的最后一个标签,代码如下: li:last-child{background:#090} ...
:nth-child(n) p:nth-child(2) 选择属于其父元素的第二个子元素的每个 p 元素。 3 :nth-last-child(n) p:nth-last-child(2) 同上,从最后一个子元素开始计数。 3 特别注意,选择的是选中对象在父元素中的第一个元素 2、基础效果演示 源代码 <!DOCTYPE html> CSS伪类选择器 .div{ width: 100...
last-child选择器查了下W3C的文档发现我想的没那么简单。 就拿:last-child举例,文档中对其的解释是: 指定属于其父元素的最后一个子元素的 p 元素的背景色 什么意思呢?我详细说明一下: 假如是 div:last-child 那么该选择器最终选择的元素是 : 对所有div标签的父元素的其最后一个子元素div 设置样式,也就是说...
这是css3中新增的选择器,意思分别是最后一个子元素和第一个子元素,不过使用的时候,考虑一下随之引起的兼容性问题。
:first-child和:last-child 用来选择某个元素的第一个子元素。//输入ul li:first-child //输入ul li:last-child 刚刚有个这方面的视频,视频的系列名称叫做 《Buid New World》 里面的第八集是讲CSS3 选择器的,有机会看看吧
li:first-child{ background:yellow; } li:last-child{ background:blue; } 2.对指定序号的子元素使用样式 li:nty-child(2){ background:yellow; }//对第二个子元素设定背景色 li:nth-last-child(2){ background:blue; }//对倒数第二个