1 <style>2 . table-striped tbody > Tr:nth-child (Odd) > td,. table-striped tbody > Tr:nth-child (odd) > th{3 Background-color:#f9f9f9;4}5 /*Nth-child (): Specifies the background color of each p belonging to the second child element of its parent element;6 nth-child (n): The selector matches the nth child element that belongs to its parent element, regardless of the type of the element, n can make a number, a keyword, or an expression7 odd and even are keywords that can be used to match sub-elements with an odd or even number subscript8 9 Nth-of-type (n): The selector matches each element of the nth child element of a particular type belonging to the parent element, n can make a number, a keyword, or an expressionTen One difference: nth-child (), the selector selects the nth child element of the parent element, regardless of type A */ - </style> - the - <div style= "margin-top:100px;" > - <table class= "table-striped" > - <tbody> + <tr> - <td>1</td> + <td>dafsdf</td> A </tr> at <tr> - <td>2</td> - <td>QQQQQQQQQ</td> - </tr> - <tr> - <td>3</td> in <td>sssssssssssss</td> - </tr> to <tr> + <td>4</td> - <td>zzzzzzzzzzzzz</td> the </tr> * </tbody> $ </table>Panax Notoginseng - </div>
Application of CSS selector Nth-child () and Nth-of-type ()