2010-08-30 17 views
4

我一直在使用谁拥有该物业的CSS样式文件的网页:有关css风格的两种背景可能吗?

body { 
    background: #7a9c12 url(images/main_background.jpg) top center no-repeat; 
    color: #bbb; 
    font: 12px/14px helvetica, arial,Sans-serif; 
} 

正如你可以看到这个代码只穿对格体顶部中心的背景图像。但是,我需要在身体标记的底部中心也有一个背景图像,我该怎么做?谢谢!

回答

2

,如果你不使用CSS3是对你的htmlbody标签层中的背景图片的选项:

html { 
    background: #7a9c12 url(images/main_background_top.jpg) top center no-repeat; 
} 

body { 
    background: url(images/main_background_bottom.jpg) bottom center no-repeat; 
} 

只要确保你只申请了坚实的背景颜色与背景html财产,否则你会覆盖图像,只能看到body背景图像。

1

使用CSS3,您可以有多个背景,用逗号分隔。请参阅documentation。例如

background: url(banner.png) top center no-repeat, 
      url(footer.png) bottom center no-repeat; 
1

对于CSS2.1,不行,这是不可能的。 对于CSS3,是的,你可以。

一个盒子的背景可以在CSS3中有 多个图层。 图层的数量由 'background-image'属性中的 逗号分隔值的数量决定。

参考:W3C

+0

感谢您的答案,我怎样才能在其中使用css3? – Sohail 2010-12-07 16:03:25