简体   繁体   English

带空格的CSS速记属性

[英]CSS shorthand attribute with gaps

Are CSS shorthands like background property working with a value-gap? CSS速记(例如background属性)是否具有值差距? I tried it with background. 我尝试了背景。 I wanted to set some background values static and the backgorund image dynamicly. 我想静态设置一些背景值,并动态设置backgorund图像。

I did the following: 我做了以下工作:

background: no-repeat contain center;

The background-image should be added later dynamicly. 应稍后动态添加background-image Did i something wrong? 我有什么问题吗? The shorthand like i used isn't working. 我使用的速记无法正常工作。 Do i have to use the single attributes ( background-repeat, background-size, background-position ...) to realise that? 我是否必须使用单个属性( background-repeat, background-size, background-position ...)来实现这一点?

The problem isn't the missing background-image. 问题不在于缺少背景图像。 The problem is with the background-size and background-position values. 问题出在背景尺寸和背景位置值上。 Unlike the rest of the longhands, values for those two have a very specific grammar: background-position followed by a / followed by background-size. 与其余的长手不同,这两个值具有非常特定的语法:background-position,后跟一个/然后是background-size。 See the spec . 参见规格

This is what it should look like: 它应该是这样的:

background: no-repeat center / contain;

You can always set a background-image separately. 您始终可以分别设置背景图像。

Some other shorthands do have mandatory values. 其他一些速记确实具有强制性值。 For example, font requires a font-size and a font-family. 例如, font需要字体大小和字体系列。 background does not have any mandatory values. background没有任何强制性值。

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

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