CSS 的作用:first-child 选择器


使用 CSS :first-child 选择器设计其父级的每一个第一个子元素 <p>。

示例

你可以尝试运行以下代码,实现 :first-child 选择器

在线演示

<!DOCTYPE html>
<html>
   <head>
      <style>
         p:first-child {
            background-color: orange;
         }
      </style>
   </head>
   <body>
      <h1>Heading</h1>
      <p>This is demo text.</p>
      <div>
         <p>This is demo text, with the first child of its parent div.</p>
         <p>This is demo text, but not the first child.</p>
      </div>
   </body>
</html>

更新时间: 2020-06-30

135 阅读

开启你的 事业

完成课程获得证书

开始
广告
© . All rights reserved.