我有几个页面在父 div 内具有不同的结构
<div class="post-formatting">
<p>some text
<em>
<a href="http://example.com">Click here</a>
</em>
</p>
</div>
<div class="post-formatting">
<p>some text
<a href="http://example-2.com">Click here</a>
</p>
<div>
<a href="http://example-3.com">Click here</a>
</div>
</div>
<div class="post-formatting">
<a href="http://example-4.com">Click here</a>
</div>
我需要为所有人设置一个通用的CSS规则<a>
<div class="post-formatting">
内的标签,无论是否是第一个 child 。
有没有办法做到这一点?谢谢
最佳答案
是的。这是非常基本的 CSS。您可以通过以下方式非常简单地实现此目的:
.post-formatting a {
/* Your style declarations here. */
}
.post-formatting a {
color: red;
font-weight: bold;
}
<div class="post-formatting">
<p>
some text
<em>
<a href="http://example.com">Click here</a>
</em>
</p>
</div>
<div class="post-formatting">
<p>some text
<a href="http://example-2.com">Click here</a>
</p>
<div>
<a href="http://example-3.com">Click here</a>
</div>
</div>
<div class="post-formatting">
<a href="http://example-4.com">Click here</a>
</div>
关于html - 子元素的 CSS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33282748/