Home > Web Front-end > Front-end Q&A > What is the way to write the singular number li in css3

What is the way to write the singular number li in css3

WBOY
Release: 2022-04-20 10:08:10
Original
2141 people have browsed it

The singular li in css3 is written as "li:nth-child(odd)"; the ":nth-child" selector is used to match the specified child element that belongs to its parent element, and the parameters in the selector are set to "Odd" means matching sub-elements whose subscripts are odd, where the sub-script of the first sub-element is "1".

What is the way to write the singular number li in css3

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

What is the writing method of singular li in css3

:nth-child(n) selector matches the Nth child element belonging to its parent element, regardless of the type of element.

n can be a number, keyword or formula.

Odd and even are keywords that can be used to match child elements whose index is odd or even (the index of the first child element is 1).

So the writing method is:

li:nth-child(odd)
Copy after login

The example is as follows:

<!DOCTYPE html>
<html>
<head>
<style> 
li:nth-child(odd)
{
background:#ff0000;
}
</style>
</head>
<body>
<ol>
  <li>Coffee</li>
  <li>Tea</li>
  <li>Milk</li>
</ol>
<p><b>注释:</b>Internet Explorer 不支持 :nth-child() 选择器。</p>
</body>
</html>
Copy after login

Output result:

What is the way to write the singular number li in css3

(Learning video sharing: css video tutorial)

The above is the detailed content of What is the way to write the singular number li in css3. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
css
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