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.
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}
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}
3, nth-child(3)
represents the third label in the selection list, and the code is as follows:
li:nth-child(3){background:#090}
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!