Css 背景:无与背景:透明有什么区别?

Css 背景:无与背景:透明有什么区别?,css,background,Css,Background,这两个CSS属性之间是否存在差异: background: none; background: transparent; background-image: none background-position: 0% 0% background-size: auto auto background-repeat: repeat background-origin: padding-box background-style: is itself a shorthand, its initial v

这两个CSS属性之间是否存在差异:

background: none;
background: transparent;
background-image: none
background-position: 0% 0%
background-size: auto auto
background-repeat: repeat
background-origin: padding-box
background-style: is itself a shorthand, its initial value is the concatenation of its own longhand properties
background-clip: border-box
background-color: transparent
  • 它们都有效吗
  • 应该使用哪一种?为什么

  • 他们之间没有区别

    如果未为
    background
    是其缩写的六个属性中的任何一个指定值,则将其设置为默认值<代码>无和透明是默认值


    显式地将
    背景图像
    设置为
    ,隐式地将
    背景颜色
    设置为
    透明
    。另一种是另一种方式。

    作为昆汀回答的传统信息,正如他正确地说,
    background
    CSS属性本身是以下内容的缩写:

    background-color
    background-image
    background-repeat
    background-attachment
    background-position
    
    也就是说,您可以将所有样式分组到一个样式中,如:

    background: red url(../img.jpg) 0 0 no-repeat fixed;
    
    这将是(在本例中):

    所以。。。设置时:
    background:none
    您的意思是所有背景属性都设置为none
    您的意思是
    背景图像:无
    和所有其他属性都处于
    初始
    状态(因为它们未被声明)。
    所以,
    background:none是:

    background-color: initial;
    background-image: none;
    background-repeat: initial;
    background-attachment: initial;
    background-position: initial;
    
    现在,当你只定义颜色(在你的例子中是透明的)时,你基本上是在说:

    background-color: transparent;
    background-image: initial;
    background-repeat: initial;
    background-attachment: initial;
    background-position: initial;
    
    我重复一遍,@Quentin正确地说,
    默认值
    透明值
    无值
    在本例中是相同的,因此在您的示例和您的原始问题中,不,它们之间没有区别

    但是!。。如果你说背景:无
    Vs
    background:red
    。。。有一个很大的区别,正如我所说,第一个将所有属性设置为
    none/default
    ,第二个将只更改
    颜色
    ,其余的保持在他的
    default
    状态

    简言之: 简短回答:不,没有任何区别(在您的示例和原始问题中)
    详细回答:是的,有很大区别,但直接取决于授予属性的属性


    Upd1:初始值(也称为默认值) 初始值其原始属性的初始值的串联:

    background: none;
    background: transparent;
    
    background-image: none
    background-position: 0% 0%
    background-size: auto auto
    background-repeat: repeat
    background-origin: padding-box
    background-style: is itself a shorthand, its initial value is the concatenation of its own longhand properties
    background-clip: border-box
    background-color: transparent
    
    请参阅更多
    背景
    说明
    

    Upd2:更好地澄清
    背景:无规格。

    补充其他答案:如果要将所有背景属性重置为其初始值(包括
    背景颜色:透明
    背景图像:无
    ),而不明确指定任何值,例如
    透明
    ,您可以通过以下方式进行操作:

    background: initial;
    

    thx的答案背景图像、背景重复的默认值是什么。。。?它们依赖于浏览器吗?如果我理解你的解释,最好使用background:none,所以没有一个值被设置为默认值?你试过你发布的内容吗??是否所有值都设置为“无”?当您设置:后台:无时,请检查此演示中的
    控制台
    ;你是说所有背景属性都设置为无。。。不是说是错的+1,这一定是公认的答案(如果它是正确的)。根据MDN,背景图像的初始值是
    none
    ,因此
    背景图像:none
    ==
    背景图像:initial
    ,因此,
    背景:none
    =
    背景:透明
    ,我guess@herman-不,他们不能。这与背景色相同:透明;背景图像:无。用户样式表可能覆盖其中一个或两个值,但它会完全像
    background color:transparent;背景图像:无是显式编写的。那么,您是说“初始”属性值(用于未指定的属性)甚至会覆盖用户代理样式表?您有任何参考资料吗?用户代理样式表实现了规范,该规范将这些属性的初始属性值定义为
    透明
    。小心,IE不支持
    初始
    。看到和