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".
The operating environment of this tutorial: Windows 10 system, CSS3&&HTML5 version, Dell G3 computer.
: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)
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>
Output result:
(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!