我正在做一个元素。
我想在主体上使用相同的背景颜色,但是当我设置主体颜色时,带有 .container-fluid
类的 div 会得到其他颜色。
如何在两者上设置相同的颜色?
这是我的代码:
body {
background-color: rgb(0, 223, 26);
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container-fluid" style="background-color:rgb(0,223,26)">
<div class="row">
<div class="offset-4 col-4 offset-4">
<div class="offset-1">
<h1 style="color:rgb(240,255,0)">Random Einstein's Quote Generator</h1>
</div>
<b><div class="randomquote" style="font-size:20px">
</div></b>
<div class="offset-3">
<button id="quotegenerator" style="font-size:14px" class="offset-1 col-4 offset-1 btn btn-primary">New Quote</button>
</div>
</div>
</div>
</div>
最佳答案
主体样式被 bootstrap CSS 覆盖,它不采用您的颜色:
body {
background-color: rgb(0, 223, 26);
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" rel="stylesheet"/>
<body>
BODY!
</body>
您可能想直接在正文中添加一个 div:
body > div {
background-color: rgb(0, 223, 26);
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" rel="stylesheet"/>
<body>
<div><!-- Added here -->
<div class="container-fluid"><!-- Removed inline CSS here -->
<div class="row">
<div class="offset-4 col-4 offset-4">
<div class="offset-1">
<h1 style="color:rgb(240,255,0)">Random Einstein's Quote Generator</h1>
</div>
<b><div class="randomquote" style="font-size:20px">
</div></b>
<div class="offset-3">
<button id="quotegenerator" style="font-size:14px" class="offset-1 col-4 offset-1 btn btn-primary">New Quote</button>
</div>
</div>
</div>
</div>
</div><!-- Added here -->
<body>
希望对您有所帮助。
关于javascript - 设置主体颜色但 div block 有不同的颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50584155/