Encountered a selector: Nth-of-type
<!DOCTYPE HTML><HTML> <Head> <Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8" /> <styletype= "Text/css">P:nth-of-type (odd)//odd{background:#cff; }P:nth-of-type (even)//even{background:#fcc; } </style> </Head> <Body> <H1>This is the title</H1> <P>The first paragraph.</P> <Div>This is a div.</Div> <Div>This is a div.</Div> <P>A second paragraph.</P> <P>A third paragraph.</P> <span>This is a span.</span> <P>A fourth paragraph.</P> <P>A fifth paragraph.</P> </Body></HTML>
Odd even another way
P:nth-of-type (2n+1);
P:nth-of-type (2n);
The difference from Nth-child
P:nth-child (2): The selector matches the 2nd child element belonging to its parent element, regardless of the type of the element. Before adding p, you need to satisfy two conditions, the second element of the parent element, and the P element.
P:nth-of-type (2): The selector matches each element of the 2nd child element of a particular type (p) that belongs to the parent element.
CSS3 selector: Nth-of-type