如果您想了解css–nth-child要交替2行的相关知识,那么本文是一篇不可错过的文章,我们将对css的nth-child进行全面详尽的解释,并且为您提供关于7.nth-of-type|nth-ch
如果您想了解css – nth-child要交替2行的相关知识,那么本文是一篇不可错过的文章,我们将对css的nth-child进行全面详尽的解释,并且为您提供关于7.nth-of-type | nth-child?【CSS】、:nth-child/:first-child/:last-child 选择器易错点、css :nth-child() 使用、CSS first-child 和nth-child 区别是什么的有价值的信息。
本文目录一览:- css – nth-child要交替2行(css的nth-child)
- 7.nth-of-type | nth-child?【CSS】
- :nth-child/:first-child/:last-child 选择器易错点
- css :nth-child() 使用
- CSS first-child 和nth-child 区别是什么
css – nth-child要交替2行(css的nth-child)
我想使用CSS3的nth-child选择器在两行厚的背景颜色之间交替,而不是在使用nth-child(奇数)时通常的一行.
The “Result” section of this jsFiddle illustrates what I want.
所以我们会有一张桌子:
ROW 1: Blue ROW 2: Blue ROW 3: Red ROW 4: Red ROW 5: Blue ROW 6: Blue
解决方法
tr { background: blue; } tr:nth-child(4n+1),tr:nth-child(4n+2) { background: red; }
n将从0开始计数.
DEMO
7.nth-of-type | nth-child?【CSS】
:nth-child/:first-child/:last-child 选择器易错点
$("tr td:first-child").css("width","35%");
上面的代码含义是:将 tr 下的第一个 td 宽度设置为 35%
很容易让人错误地理解为,将 td 下的第一个子元素的宽度设置为 35%
css :nth-child() 使用
1. :nth-child(x) 里面直接写数字,x从1开始
2. :nth-child(2n) 倍数写法
3. :nth-child(3n+4) 倍数分组分配 :分成n分,每份3个,取每份的第四个
4. :nth-child(-3n+4) 反向倍数分组分配 :分成n分,每份3个,取每份的第四个
5. :nth-child(oven)/ :nth-child(odd) 奇偶匹配
CSS first-child 和nth-child 区别是什么
css first-child和nth-child区别:1、first-child是伪类选择器,表示匹配父元素的第一个子元素;2、nth-child表示匹配父元素的第n个子元素。
本教程操作环境:windows7系统、
推荐:《css视频教程》
first-child
E:first-child是伪类选择器,
立即学习“前端免费学习笔记(深入)”;
匹配父元素的第一个子元素E
从说明可以看出E是你要选择的第一个子元素,而不是父元素。一开始,误以为E:first-child是E的第一个子元素。
:nth-child(n)
匹配父元素的第n个子元素E
E也是子元素,而且也只能匹配父元素下第n个子元素。n是从1开始计数
<ul> <li>l1</li> <li>l2</li> <li>l3</li> </ul>
若要选择
若要选择
<div> <h1>h1</h1> <p>p1</p> <p>p2</p> <p>p3</p> </div>
这时选择第一个p元素,应用p:first-child则会出现错误,因为p的父元素是div,而对于div来说,它的第一个子元素不是p,而是h1,所以如果选择器p:first-child,则会出错。
同理,E:last-child``E:only-child与上面的一样,E元素必须是其父元素的最后一个子元素或唯一一个子元素才可以
更多编程相关知识,请访问:编程教学!!
以上就是CSS first-child 和nth-child 区别是什么的详细内容,更多请关注php中文网其它相关文章!
今天的关于css – nth-child要交替2行和css的nth-child的分享已经结束,谢谢您的关注,如果想了解更多关于7.nth-of-type | nth-child?【CSS】、:nth-child/:first-child/:last-child 选择器易错点、css :nth-child() 使用、CSS first-child 和nth-child 区别是什么的相关知识,请在本站进行查询。
本文标签: