css - 使用 .bg- 类覆盖 Jumbotron 背景颜色

标签 css bootstrap-4

目前我正在使用 Bootstrap。对于主题,我使用 Bootswatch 主题。 我注意到 Jumbotron 在每个主题中都有相同的丑陋灰色背景。所以我想使用 .bg-改变颜色的类。

我还看了:

处理特异性

Sometimes contextual background classes cannot be applied due to the specificity of another selector. In some cases, a sufficient workaround is to wrap your element's content in a with the class.

所以这也是我尝试过的。

我尝试过的:

<div class="jumbotron bg-success">
  <h1>Hello, world!</h1>
  <p>...</p>
  <p><a class="btn btn-primary btn-lg" role="button">Learn more</a></p>
</div>

<div class="bg-success">
  <div class="jumbotron">
    <h1>Hello, world!</h1>
    <p>...</p>
    <p><a class="btn btn-primary btn-lg" role="button">Learn more</a></p>
  </div>
</div>

但这不起作用,因为 bg- 类没有覆盖超大屏幕背景颜色。

示例:http://www.bootply.com/yhvhdor7lr

编辑

相关:https://github.com/twbs/bootstrap/issues/10202

最佳答案

div 将从 css 的最后一条规则中获取背景。例如,如果在样式表中,.jumbotron 类在第 5 行,而 .bg-success 都有 background-color 属性,它将取最后一行。

[试试这个 bootply]{ http://www.bootply.com/a123L6HQRi }.将一个类移动到另一个类之上,然后按运行,查看结果。

但是你使用的是CDN,不能改变规则的顺序或者添加!important来解决。也许您应该考虑添加自定义样式表来解决这个问题。

关于css - 使用 .bg- 类覆盖 Jumbotron 背景颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25787423/

相关文章:

html - 如何通过css给图片添加url?

css - 如何创建图像缩放效果(不悬停)

html - Bootstrap 4 - Scrollspy 不工作

html - 如何将包含两个 div 的列拆分为在较小的屏幕尺寸上并排放置的 div

html - 删除 flex 元素行之间的间隙

html - 选中和取消选中复选框

jquery - 调整窗口大小后 Owl Carousel 幻灯片消失

javascript - 如何使用 "position: absolute"水平居中元素?

javascript - 在中小屏幕设备上隐藏侧边栏

javascript - 使用 ngb-carousel 在单个 slider 页面中显示多个图像