nth-child选择(小研究)
来源:互联网 发布:floydwarshall 算法 编辑:程序博客网 时间:2024/06/07 23:26
前言:我也不知道说什么,就是感觉这个还是挺有用的!!
先构造一下简单的列表
<style> *{ margin:0; padding:0; list-style:none; text-decoration: none; } body{ padding:50px; } li{ display: inline-block; border:1px solid gray; padding:5px 10px; color:red; font-size: 10px; }</style><ul> <li>列表1</li> <li>列表2</li> <li>列表3</li> <li>列表4</li> <li>列表5</li> <li>列表6</li> <li>列表7</li> <li>列表8</li></ul>
第一个或者最后一个
li:first-child{ color:blue; } li:last-child{ color:blue; }
选择第几个
li:nth-child(2){ color:blue;}
选择前3个
li:nth-child(-n+3){ color:blue;}
从第四个到最后
li:nth-child(n+4){ color:blue;}
选择第二个到第五个
li:nth-child(n+2):nth-child(-n+5){ color:blue;}
奇数偶数
li:nth-child(even){ color:blue;}
li:nth-child(odd){ color:blue;}
等差数列
li:nth-child(3n+1){ color:blue;}
第三个到第七个之间的奇数行不包括3\7
li:nth-child(n+4):nth-child(-n+6):nth-child(2n+1){ color:blue;}
第三个到第七个之间的奇数行包括3\7
li:nth-child(n+3):nth-child(-n+7):nth-child(2n+1){ color:blue;}
选择最后两个
li:nth-last-child(-n+2){ color:blue;}
反选(:not)
li:not(:nth-child(2n+1)){ color:blue;}
扩展
如果列表中掺杂了其余的标签,不是纯粹的一样的标签的话就可以用nth-of-type
,用法都是一样的!!
阅读全文
0 0
- nth-child选择(小研究)
- nth-child 的一些小尝试
- nth-child()IE兼容问题
- :nth-child()
- jQuery学习之探究nth-child(N)选择符
- 使用负的 nth-child 来选择元素
- nth-child(n)的IE8兼容问题
- CSS3属性(3):nth-child()属性
- CSS3子元素选择方法nth-child和nth-of-type
- 选择中的:nth-child(n)和:nth-of-type(n)的区别
- css:first-child、last-child、nth-child、 nth-last-child
- nth-child(odd)和nth-child(even)
- :nth-child选择器
- CSS 选择器nth-child
- CSS3:nth-child() 选择器
- nth-child()选择器
- :nth-child的用法
- 精通:nth-child
- Python print()函数
- 基于PXE ,Kickstart ————从网卡启动装系统
- otter系列—otter_manager 安装配置(快速开始)
- redis 报 error NOTAUTH Authentication required
- XML
- nth-child选择(小研究)
- 工作日常--遇到angular报错‘$digest already in progress’
- MFC显示位图(2-2)
- 欢迎使用CSDN-markdown编辑器
- Leetcode 743. Network Delay Time
- java反射之包装类和基础数据类型的坑(分享个反射工具方法)
- Android 项目中常用小知识点.
- JavaScript 计时事件
- nginx代理后,获取request的ip