【问题标题】:Background color not changing from white背景颜色不会从白色改变
【发布时间】:2017-12-15 15:37:31
【问题描述】:

由于某种原因,背景颜色拒绝从白色改变。我试图让它在标题下从白色变为黑色,但它拒绝改变。将 "background-color:" 放在正文 SCSS 中似乎并没有改变它。

我不确定我的 SCSS 中是否有什么东西在我没有意识到的情况下简单地覆盖了背景颜色?

非常感谢任何帮助

SCSS:

*{
margin: 0;
padding: 0;
text-decoration: none;
list-style: none;
background-color: '#010101';
}

#wrapperHeader {
width: 100vw;
height: 210px; /* height of the background image? */
background:url(images/header.png);
}

div#wrapperHeader div#header {
width: 100vw;
height:100px;
margin:0 auto;
}

div#wrapperHeader div#header img {
width: 100vw ; /* the width of the logo image */
height: 210px ; /* the height of the logo image */
margin:0 auto;
}

header {
color: white;
background-color: dimgrey ;
clear: left;
text-align: center;
}

.toggle_menu{
position: fixed;
padding: 17px 20px 15px 15px;
margin-top: 210px;
color: white;
cursor: pointer;
background-color: #000;
z-index: 1000000;
font-size: 2em;
opacity: 0;

}

.sidebar_menu{
position: fixed;
width: 100vh;
max-width: 250px;
margin-left: 0px;
overflow: hidden;
height: 100vh;
max-height: 100vh;
background-color: rgba(17, 17, 17, 0.9);
opacity: 0,9;
transition: all 0.3s  ease-in-out;
}

.fa-times{
right: 10px;
top: 10px;
opacity: 0.7;
cursor: pointer;
position: absolute;
color: red;
transition: all 0.3s  ease-in-out;

}

.fa-times:hover{
opacity: 1 ;
}

.boxed_item {
font-family: 'Open Sans';
font-weight: 200;
padding: 10px 20px;
display: inline-block;
border: solid 2px white;
box-sizing: border-box;
font-size: 22px;
color: white;
text-align: center;
margin-top: 70px;

}

.logo_bold{
font-weight: 800;
}

.logo_title{
color: white;
font-family: 'Open Sans';
font-weight: 200;
font-size: 12px;
text-align: center;
padding: 5px 0px;
}

.nav_selection{
margin: 0, 0;
display: block;
width: 200;
margin-top: 100px;
margin-left: 5px;

}

.nav_item{
font-weight: 200;
font-family: 'Open Sans';
color: white;
padding: 15px 0;
font-size: 20px;
color: #D8D8D8;
border-bottom: solid 2px #D8D8D8;
transition: all 0.3s  ease-in-out;

}

.hide_menu{
margin-left: -250px;

}

.opacity_one{
opacity: 1;
}

.disabled {
pointer-events:none; //This makes it not clickable
opacity:0.6; 

font-weight: 200;
font-family: 'Open Sans';
color: white;
padding: 15px 0;
font-size: 20px;
color: #D8D8D8;
border-bottom: solid 2px #D8D8D8;
transition: all 0.3s  ease-in-out;
}

【问题讨论】:

  • 请提供MCVE
  • 要调试的代码很多......无论如何,这里的问题是特异性,这就是我能说的全部
  • 尝试设置不带引号的颜色:background-color: #010101;
  • @xs0 头部下方的部分仍然是白色的,不确定设置容器并将其设置为头部下方的黑色是否有效?
  • 试试这个背景:#dddddd !important;

标签: html css sass


【解决方案1】:

在三个地方,您可以提供三种不同样式的背景颜色代码。 请遵循任何格式。

  1. 切勿在引号中指定颜色。你已经在*{ background-color: '#010101'; } 中给出了它,记住这一点。应该是*{ background-color: #010101; }
  2. 您提供了background-color: dimgrey ;,因此每次颜色名称无效时,您都提供了相应的颜色代码。

这是您必须进行更改的标题部分。对于dimgrey,颜色代码为:#696969,因此您的代码将为:

header {
color: white;
background-color: #696969; // check this line.
clear: left;
text-align: center;
}

它将改变标题部分的背景颜色。你只需要检查那部分。

  1. 其他样式可能会覆盖页眉的背景。在这种情况下,您必须将!important 放入如下代码中:

header {
color: white;
background-color: #696969 !important; // check this line.
clear: left;
text-align: center;
}

如果对你有帮助,请告诉我。

【讨论】:

  • 它将标题颜色更改为背景颜色和导航栏的内部,但是,它下面的空白仍然是白色的,刚刚看到你的编辑我会在两秒钟内更新
  • @AdamSteele 你能分享一下屏幕截图吗?修改后?
  • 我希望gyazo没事! gyazo.com/e5e6fcd8dc6f9503c8573ecc047180f8 我也设法包含了代码
  • @AdamSteele 是的,我会没事的
  • @AdamSteele 仍然面临这个问题。让我知道您在哪一部分遇到问题
【解决方案2】:

改变背景颜色:'#010101';这到 背景颜色:'#010101!important';

【讨论】:

  • gyazo.com/5638d70b57ee0f516fcf5e4488d5bc85 这样做会改变一切的颜色,但我尝试在所有其他颜色声明之后添加 !important 但这也不起作用
  • 哦!请为您要更改颜色的内容提供一个 id,然后将其添加到 css 中,例如:#name { background-color: #010101 !important;我认为您已将通用选择器的背景颜色指定为 #010101
  • 所有其他东西都有带有背景颜色集的 ID,如我上面的 SCSS 所示,无论如何它似乎都超过了它们
  • *{ 边距:0;填充:0;文字装饰:无;列表样式:无;背景颜色:'#010101';自从您将其分配给通用选择器 * 以来,这将覆盖所有内容
  • 那么我如何才能让背景颜色不超过一切,这样我仍然可以保持我的配色方案??
猜你喜欢
  • 1970-01-01
  • 2014-06-21
  • 2014-04-21
  • 2021-01-23
  • 2011-06-15
  • 2022-11-01
  • 2014-08-21
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多