背景:透明;对比背景:0 0;差异与威胁

background: transparent; vs background: 0 0; differences and threats

我注意到 background: transparent 使用 less 变成了 background: 0 0;。我在 1.4.1 版本中使用 grunt-contrib-less,该版本使用 "less": "~2.7.1" 将 less 转换为 css。后台这些0 0是干什么用的?使用 background: 0 0 而不是 background: transparent 有什么好处吗?我试图 google 这个,但我找不到任何可以解释我的东西

background: 0 0 将背景位置设置为 background-position: 0 0 而不是透明。

background-color初始值透明

background: none 设置 background-image: none

来自 MDN:(大胆的矿)

The background CSS shorthand property assigns explicit given values and sets missing properties to their initial values.

两个版本:background: transparentbackground: 0 0; 将所有背景属性重置为其初始值,除了每个版本都明确设置自己的特定背景 属性。

background: transparent - 将 background-color 设置为 transparent

background: 0 0;background-position 设置为 0 0

交换它们应该没有问题(所以没有 'threats')

实际上,使用 属性 background: 0 0; 而不是 background: transparent
你不会得到任何待遇,这个 background: 0 0

background-image: initial;
background-position-x: 0;
background-position-y: 0;
background-size: initial;
background-repeat-x: initial;
background-repeat-y: initial;
background-attachment: initial;
background-origin: initial;
background-clip: initial;
background-color: initial;

每个背景 属性 设置为初始值,background position 设置为 0 0 并回答您的另一个问题,为什么 Less 将 background:transparent 更改为 background: 0 0 是 IE7 或更低版本不支持 transparent 属性 所以 Less 正在将其更改为另一个 shorthand 符号,它给出相同的输出