【问题标题】:CSS styling the 2nd nested div inside of a parent divCSS 样式化父 div 内的第二个嵌套 div
【发布时间】:2021-11-10 01:13:33
【问题描述】:

我有一些嵌套的 div 用作警报框。我想在父 div 上使用一个类来驱动其中 div 的样式。

<div class='aa-callout aa-prime'>
  <div class='row p-1 h-100'>
    <div class='col-1 d-flex align-items-center'>
      <i class="fal fa-exclamation-circle fa-3x text-white mx-auto"></i>
    </div>  
    <div class='col-11'>
      <h4>Blue is for information</h4>
      <p>Sed ut perspiciatis unde.</p>
    </div>
  </div>  
</div>

我需要让包含

  • 嗨:)内部的div也有类,你为什么不使用它们而不是像div一样访问它们。
  • 为什么不简单地.aa-prime &gt; div &gt; div:first-child
  • @Azu - 这些是动态的,我们想将一个类应用到父类并让其他一切都到位。
  • @j08691 - 谢谢 - 与我使用的解决方案非常相似。

标签: css bootstrap-4 css-selectors


【解决方案1】:

如果该结构是固定的(即非动态的),您可以使用此选择器:

.aa-prime > div:first-child > div:first-child { ...

(注意::nth-child(2) 不起作用,因为第二个 div 是第一个 div 的子代)

【讨论】:

  • 谢谢!还要解释清楚为什么 nth-child(2) 不起作用。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-09-20
  • 1970-01-01
  • 2017-04-20
  • 2016-02-18
  • 2015-11-12
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多