【问题标题】:css difference between background: and background-image:背景:和背景图像之间的CSS区别:
【发布时间】:2017-01-29 04:46:43
【问题描述】:
快速简单的问题
在以下外部 CSS 页面示例中;
body {
background-image: url(background.jpg);
}
header {
background: url(background.jpg);
}
我知道它们会影响不同的元素选择器,我的问题是使用背景与背景图像有什么区别?一个人可以访问另一个人的特定属性吗?谢谢,麻烦您了。
【问题讨论】:
标签:
css
background
background-image
between
difference
【解决方案1】:
在背景属性中可以添加background-color、repeat、no-repeat等图片属性,但在background-image属性中只能添加图片。
background-image: url("img_tree.png");
background-repeat: no-repeat;
background-position: right top;
background-attachment: fixed;
在后台属性中,您可以在一行中完成所有这些操作
background: #ccc url(paper.gif) no-repeat;
【解决方案2】:
通过使用背景,您需要指定其他参数来设置页面的背景。如果你只是使用背景图片,它只需要一个参数。
background: bg-color bg-image position/bg-size bg-repeat bg-origin bg-clip bg-attachment initial|inherit;