CSS的作用:nth-​​child(n)选择器

使用CSS:nth-child(n)选择器来设置每个<p>元素的样式,这些元素是使用CSS父元素的第二个子元素。您可以尝试运行以下代码来实现:nth-child(n)选择器

示例

<!DOCTYPE html>
<html>
   <head>
      <style>
         p:nth-child(4) {
            background: orange;
            color: white;
         }
      </style>
   </head>
   <body>
      <p>This is demo text 1.</p>
      <p>This is demo text 2.</p>
      <p>This is demo text 3.</p>
      <p>This is demo text 4.</p>
      <p>This is demo text 5.</p>
      <p>This is demo text 6.</p>
   </body>
</html>