简体   繁体   English

CSS无效的属性值?

[英]CSS Invalid Property Value?

I don't understand what's wrong with this?我不明白这有什么问题? I'm watching a tutorial and it seems to work fine on the video but both mozilla and chrome ignore this code and marks it as an invalid property value.我正在看一个教程,它似乎在视频上运行良好,但 mozilla 和 chrome 都忽略了此代码并将其标记为无效的属性值。

.btn {
    background-color: #4FB69F url("img/texture.png") no-repeat right top;
} 

change改变

background-color:

to

background:

Because background is a shorthand property for因为background是一个速记属性

  • background-color背景颜色
  • background-image背景图片
  • background-position背景位置
  • background-repeat背景重复
  • background-attachment背景附件

Another possible cause could be that you have a "Hidden Character" in the css property or value.另一个可能的原因可能是您的 css 属性或值中有一个“隐藏字符”

To fix that, copy the code directly from you IDE to some "Hidden Character" detector like this one https://www.soscisurvey.de/tools/view-chars.php ,delete the 'bad' characters and then save your code again without the bad characters.要解决此问题,请将代码直接从您的 IDE 复制到一些“隐藏字符”检测器,例如https://www.soscisurvey.de/tools/view-chars.php ,删除“坏”字符,然后保存您的代码再次没有坏字符。

Bonus: If you are using a JetBrains ide like WebStorm, this plugin can help you https://plugins.jetbrains.com/plugin/7448-zero-width-characters-locator奖励:如果您使用像 WebStorm 这样的 JetBrains ide,这个插件可以帮助您https://plugins.jetbrains.com/plugin/7448-zero-width-characters-locator

Not directly a solution but a typo in CSS property value caused similar issue for me:不是直接的解决方案,而是 CSS 属性值中的错字给我造成了类似的问题:

.PokeCard {
border: 2px solic mediumseagreen;
}

The problem was a typo solic instead of solid .问题是错别字solic而不是solid

在此处输入图片说明

If you are using inverted commas in your css. 
Please remove inverted commas from  your css file.

For Example,
Please find below css and find difference between both css
.row{
     margin-left:'-16px !important';
    margin-right:'0px !important';
}

.row{
    margin-left:-16px !important;
    margin-right:0px !important;
}
background-color: #4FB69F; 
background-image: url('images/texture.png'); 
background-repeat: no-repeat; 
background-position: right top;

Within the image url requires ' not " Background position is separate from no repeat and ; between each element control图像url内要求''背景位置是分开的,没有重复和;在每个元素控件之间

I had similar problem .我有类似的问题。

I tried to apply background but there was a typo.我试图应用背景,但有一个错字。

what i tried to in CSS我在 CSS 中的尝试

我的 CSS

and I got this error我收到了这个错误

我得到的错误

simply remove the double quotes from the value.只需从值中删除双引号。 as the hex value in css is not in double quotes.因为 css 中的十六进制值不在双引号中。

这工作正常

Instead of writing:而不是写:

.btn {
  background-color: #ffffff;
  background-image: url("img_tree.png");
  background-repeat: no-repeat;
  background-position: right top;
}

You can use the shorthand property background:您可以使用速记属性背景:

.btn {
  background: #ffffff url("img_tree.png") no-repeat right top;
}

It does not matter if one of the property values is missing, as long as the other ones are in this order.缺少一个属性值无关紧要,只要其他属性值按此顺序即可。 know more 了解更多

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM