html - 子元素的 CSS

标签 html css css-selectors

我有几个页面在父 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/

相关文章:

css - Mageno 模块的想法

CSS 选择器最佳实践

html - 如何在 Bootstrap 3 输入组中使按钮全宽?

c# - 无法让我的 Html &lt;input&gt; 按钮默认为我选择的颜色

html - 在移动屏幕上,我的 div 显示不需要的白色边框

javascript - IE点击子项不关注父项,父项有tabindex=0

jQuery 选择器问题

html - 多个具有不同颜色的 href

jquery - 我需要使用 jQuery 将一个 div 替换为另一个 div

javascript - 基于 web 的 javascript 游戏中的资源文件