2023使用 CSS 为作为其父级的第二个子级的每个元素设置样式

 所属分类:web前端开发

 浏览:46次-  评论: 0次-  更新时间:2023-09-27
描述:更多教程资料进入php教程获得。 要使用 CSS 为作为其父级的&#31532...
更多教程资料进入php教程获得。

使用 CSS 为作为其父级的第二个子级的每个元素设置样式

要使用 CSS 为作为其父级的第二个子级的每个

元素设置样式,请使用 CSS :nth-child(n) 选择器。

示例 h2>

您可以尝试运行以下代码来实现:nth-child(n)选择器

Live Demo

<!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>
 标签:
积分说明:注册即送10金币,每日签到可获得更多金币,成为VIP会员可免金币下载! 充值积分充值会员更多说明»

讨论这个素材(0)回答他人问题或分享使用心得奖励金币

〒_〒 居然一个评论都没有……

表情  文明上网,理性发言!