CSS 嵌套帮助!我需要的元素仅对父类做出反应,基本上在每个类级别都未设置

问题描述 投票:0回答:1
css nested background-color
1个回答
0
投票

您的帖子中没有包含任何屏幕截图,因此很难准确猜测您要解决的问题是什么。

CSS 的基本技术是直接应用于元素的任何样式都会覆盖它们从其祖先继承的任何样式。您不需要“取消设置”从祖先继承的样式,您需要覆盖它们。

.bg-light {    
  background: white;
  color: black;
}

.bg-dark {
  background: black;
  color: white;
}     
<div class="container mt-3">
    <h2>Contextual Backgrounds</h2>
        <p>Use the contextual background classes to provide "meaning through colors".</p>
        <div class="bg-dark">
            <h1>Outer</h1>
            <p>outer text</p>
            <div class="bg-light">                 
                <h1>Inner</h1>
                <p>Inner text</p>
            </div>
        </div>
</div>

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.