使用CSS为其父元素的第一个子元素的每个
元素设置样式
要设置作为其父级第一个子级的每个<p>元素的样式,请使用CSS:first-child选择器。
示例
您可以尝试运行以下代码来实现: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>热门推荐
6 祝福语简短七夕
10 新年祝福语简短创意兄弟
11 敏字的祝福语简短
12 简短正能量生日祝福语
13 进驻新居的祝福语简短
14 小清新的祝福语简短
15 给孙子祝福语简短独特
16 送给客户的祝福语 简短
17 新年简单祝福语简短好看
18 关云生字祝福语简短