我正在寻找一种方法来设置第一个 <h1>
的样式<body>
的后代, 或第一个 <h2>
<div>
的后代.我尝试使用 :first-child
但这似乎是任何第一个 child ......
有没有办法在纯 CSS 中指定“<h1>
中的第一个 <body>
”或“每个 <h2>
中的第一个 <div>
”?
最佳答案
你可能想要 :first-of-type
:
div > h2:first-of-type {
color: red;
}
body > h1:first-of-type {
color: red;
}
关于html - 仅设置文档中第一个 h1 的样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46160482/