当前位置:首页 > 未分类

first-child 不起作用的原因

admin3年前 (2024-01-15)未分类918

CSS3—first-child 不起作用的原因

1、first-child、last-child、nth-child(n)、nth-child(2n)、nth-child(2n-1)、nth-child(odd)、nth-child(even)、nth-last-child(3)(倒数第三个)

注意点: 选择器匹配属于其父元素的第 N 个子元素,不论元素的类型。

1、先找到该伪类调用者(元素)的父类

2、其次找到父类下的第n个子元素

3、最后看该子元素是不是1中的伪类调用者,如果是,则应用css,否则不应用

有时候first-child或者nth-child(1) 不起作用的原因,如下:

/*此时first-child不起作用,是因为.tap_con的父元素win的第一个子元素是.top,此时找到第一个子元素,但是其并不是.tab_con*/

<style>

.tab_con:first-child{

background:#090 !important;

}

.tab_con:nth-child(1){

background:#090 !important;

}

</style>

<div id="win">

<div class="top">

</div>

<div class="tab_con">

</div>

<div class="tab_con">

</div>

</div>


原文链接:https://blog.csdn.net/mjavaa/article/details/129003048

扫描二维码推送至手机访问。

版权声明:本文由web开发技术分享发布,如需转载请注明出处。

本文链接:https://www.htmlcmf.cn/?id=8

分享给朋友:

相关文章

jquery的ajax设置为同步

jquery的ajax设置为同步在使用$.get或者$.post的时候,前面加上$.ajaxSettings.async = false;使用完之后再设置为异步$.ajaxSettings.async = true; 而在使用$.…

使用requireJS导致引用文件加载不到的解决办法

近期项目中需要使用【复制到剪切板】的功能,故引入clipboard.min.js,完成该功能。但在使用时发现,页面总是报错:clipboardJS is not defined。查找资料发现,clipboard为全局变量,而被require…

css文字颜色渐变

background-size: 100%; background-repeat: repeat; background-clip: text; -webkit-background-clip: …

Js生成随机数/随机字符串的5种方法

Js生成随机数/随机字符串的5种方法:方法1:使用randomStringfunction randomString(e) {   e = e || 8;&n…

nginx 设置某个目录只允许访问指定后缀文件

server {        listen 80;        server_name your…

HTML点击跳转对应应用(邮箱、手机、微信、QQ)

1、点击邮箱号跳转到邮箱应用 (已测试)<a href="mailto:support@xxx.com">邮箱:mailto:support@xxx.com</a>2、点击手机号跳转到拨…