【问题标题】:background attribute in CSSCSS中的背景属性
【发布时间】:2010-11-05 15:36:06
【问题描述】:
background:#777777 none repeat scroll 0 0;

它包含的 5 个属性是 background-color、background-image、background-repeat、background-attachment 和 background-position。

我的问题是:

如果 background-image 没有,background-repeat、background-attachment 和 background-position 是否无用? 因为根据文档,这些都是用来改变背景图像的。

【问题讨论】:

    标签: css background


    【解决方案1】:

    如果您只想要背景颜色,请考虑使用background-color 属性而不是背景。

    【讨论】:

    • 请记住,背景颜色不会覆盖其他地方设置的背景图像...
    【解决方案2】:

    你可以简单地写

    background:#777777;
    

    或者,

    background-color:#777777;
    

    所有这些属性只影响图像。

    一般来说,如果一个 CSS 属性设置了多个值(例如,backgroundborderfont),则不需要指定所有值;您未指定的任何值都将保留为默认值。

    【讨论】:

    • 哦,背景:#777777;这个版本比背景更紧凑:#777777 none
    【解决方案3】:

    是的。没有它,它们就没有意义。

    【讨论】:

    • 所以这是在浪费代码,对吧?同背景:#777777 none?
    • 是的。如果你只想设置背景颜色,你可以做 background-color: #777777;
    猜你喜欢
    • 2019-10-13
    • 1970-01-01
    • 1970-01-01
    • 2011-09-19
    • 1970-01-01
    • 2011-05-12
    • 1970-01-01
    • 2018-07-04
    • 1970-01-01
    相关资源
    最近更新 更多