背景:和背景图像之间的CSS区别:

Posted

技术标签:

【中文标题】背景:和背景图像之间的CSS区别:【英文标题】:css difference between background: and background-image: 【发布时间】:2017-01-29 04:46:43 【问题描述】:

快速简单的问题 在以下外部 CSS 页面示例中;

body 
  background-image: url(background.jpg);

header 
  background: url(background.jpg);

我知道它们会影响不同的元素选择器,我的问题是使用背景与背景图像有什么区别?一个人可以访问另一个人的特定属性吗?谢谢,麻烦您了。

【问题讨论】:

相关帖子 - What is the difference between background and background-color 【参考方案1】:

在背景属性中可以添加background-colorrepeatno-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;

【讨论】:

以上是关于背景:和背景图像之间的CSS区别:的主要内容,如果未能解决你的问题,请参考以下文章

CSS常见技巧

CSS3 - 在精灵图像的“背景位置”之间淡入淡出

在css中设置图片的背景图,怎么设置图片纵向拉伸

急!!如何用css实现背景图片纵向平铺???

仅在 html css 中将缩略图的背景图像网格放大到更高的分辨率

CSS3中背景属性的主要区别是啥?