What is the usage of odd and even in css3

WBOY
Release: 2022-04-28 16:03:37
Original
6891 people have browsed it

In CSS3, odd and even are used as keywords in pseudo-class selectors to select specified elements. odd represents odd elements and even represents even elements; odd and even are often used with ":nth-child(n )" selector, the syntax is "element: selector (odd or even) {css style code}".

What is the usage of odd and even in css3

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

What is the usage of odd and even in css3

odd represents an odd number and even represents an even number.

odd and even are often used to select specified elements in pseudo-class selectors.

The example is as follows:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"> 
<title>菜鸟教程(runoob.com)</title> 
<style> 
p:nth-child(odd)
{
background:#ff0000;
}
p:nth-child(even)
{
background:#0000ff;
}
</style>
</head>
<body>
<h1>This is a heading</h1>
<p>The first paragraph.</p>
<p>The second paragraph.</p>
<p>The third paragraph.</p>
<p><b>注意:</b> Internet Explorer 8 and以及更早版本的浏览器 :nth-child()选择器.</p>
</body>
</html>
Copy after login

Output result:

What is the usage of odd and even in css3

(Learning video sharing: css video tutorial)

The above is the detailed content of What is the usage of odd and even in css3. 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