How to select the first element in css

coldplay.xixi
Release: 2023-01-05 16:13:07
Original
8866 people have browsed it

How to select the first element in css: 1. [first-child] means the first tag in the selection list; 2. [last-child] means the last tag in the selection list; 3. [nth-child(3)] represents the third label in the selection list.

How to select the first element in css

The operating environment of this tutorial: windows7 system, css3 version, DELL G3 computer.

How to select the first element in css:

1, first-child

first-child represents the first tag in the selection list . The code is as follows:

li:first-child{background:#090}
Copy after login

The above means, the background color of the first li module in the li list.

2, last-child

last-child represents the last tag in the selection list, the code is as follows:

li:last-child{background:#090}
Copy after login

3, nth-child(3)

represents the third label in the selection list, and the code is as follows:

li:nth-child(3){background:#090}
Copy after login

The 3 in the above code can also be changed to other numbers, such as 4, 5, etc. If you want to choose a label, just fill in the number.

4. nth-child(2n)

This means selecting the even-numbered tags in the list, that is, selecting the 2nd, 4th, 6th... tags.

Related tutorial recommendations: CSS video tutorial

The above is the detailed content of How to select the first element in css. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!