Home > Web Front-end > HTML Tutorial > css的:first-child伪类选择器用法介绍_html/css_WEB-ITnose

css的:first-child伪类选择器用法介绍_html/css_WEB-ITnose

WBOY
Release: 2016-06-24 11:30:48
Original
1856 people have browsed it

css的:first-child伪类选择器用法介绍:
此选择器能够匹配元素集合中第一个元素。
:first-child伪类选择器要和其他选择器配合使用,例如:

 

li:first-child
Copy after login

以上代码可以匹配li元素集合中第一个li元素。
代码实例如下:

<!DOCTYPE html><html><head><meta charset="utf-8"><meta name="author" content="http://www.softwhy.com/" /><title>蚂蚁部落</title><style type="text/css">li:first-child{color:green;}</style></head><body><ul>  <li>html专区</li>  <li>Div+css专区</li>  <li>Jquery专区</li>  <li>Javascript专区</li></ul></body></html>
Copy after login

 

以上代码可以将li元素集合中第一个li元素中的字体颜色设置为绿色。

原文地址是:http://www.softwhy.com/forum.php?mod=viewthread&tid=11765

更多内容可以参阅:http://www.softwhy.com/divcss/

 

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