Get the App
SLTechnology News&Howtos  ›  Development  › 

How css selects only even rows

Shulou Source: shulou.com Published: 2022-06-02 16:32:23 09月30日 Update

This article mainly explains "how to select even rows for css". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "how css chooses only even rows".

In css, you can use the pseudo-class selector ": nth-child ()" to select even rows of regular elements such as a table or li. The syntax "element: nth-child (2n) {style}" or "element: nth-child (even) {style}".

The operating environment of this tutorial: windows7 system, CSS3&&HTML5 version, Dell G3 computer.

In css, you can use the pseudo-class selector ": nth-child ()" to select even rows. The css3 pseudo-class selector: nth-child () allows you to select even rows of regular elements such as tables or li.

The nth-child (n) selector matches the nth child element of the parent element, and there is no restriction on the element type. N can be a number, a keyword, or a formula.

Even rows can be selected when n is the keyword "even" or the formula "2n".

Select the syntax for even-numbered lines:

Element: nth-child (2n) {style} element: nth-child (even) {style}

Example:

P:nth-child (2n) {background:#ff0000;} li:nth-child (even) {background:# AFEEEE;}

This is the first paragraph.

This is the second paragraph.

This is the third paragraph.

This is the fourth paragraph.

Item 1, item 2, item 3, item 4.

Effect picture:

At this point, I believe you have a deeper understanding of "css how to choose only even rows". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Tags: Select even number element style paragraph this is formula key keyword content table rule grammar learning practical deeper three size interest practicality Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi Docker Apple vpn Linux