Home > Web Front-end > HTML Tutorial > css学习选择器之:nth-child(n)_html/css_WEB-ITnose

css学习选择器之:nth-child(n)_html/css_WEB-ITnose

WBOY
Release: 2016-06-24 11:38:07
Original
1300 people have browsed it

今天新学习了一个小效果,网站比如说实现间行颜色变化,比如说一行黑,一行白,好吧,斑马就出现了,当你鼠标触碰某一行,颜色背景变化,尤其是当你连接数据库时,简单的代码就显得很重要了.

这时候一个有意思的朋友出现了,:nth-child(n)  一直在那蹦?着说“找我呀”,这个是说选择器匹配属于其父元素的第N个子元素,从0开始,比如说p:nth-child(2)指下标为2的p元素,就是第3个元素;然后如果想实现奇偶行不同,奇数可以直接用odd,偶数直接用even,方便,如果用(2n+1),(2n)也OK的;

.history-content:nth-child(2n+1) {	background: #D8F0E7;}.history-content:nth-child(2n) {	background: #eee;}.history-content:hover {	background: #fff;}
Copy after login

跟下面效果是一样一样的:

.history-content:nth-child(odd) {	background: #D8F0E7;}.history-content:nth-child(even) {	background: #eee;}.history-content:hover {	background: #fff;}
Copy after login
最后效果是这样的,一行灰色,一行绿色,触碰成白色


菜鸟学习,如有更好的,敬请交流!哈

版权声明:本文为博主原创文章,未经博主允许不得转载。

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template