2012-11-23 88 views
1

我有这样的代码:2背景上的身体:如何设置高度为背景

body{ 
    margin: 0px; 
    padding: 0px; 
    background-image: url(images/header.png), url(images/footer.png); 
    background-repeat: repeat-x, repeat; 
    background-height: 50px , 400px; /* ?? */ 
    background-position: 0% 0%, 0% 100%; 

} 

我可以给footer.png的高度将在特定高度重复?

+2

我不确定我是否理解。 “在特定高度重复”是什么意思? – BoltClock

+0

我的意思是第二个图像的高度为200像素或某物,但我需要重复该图像,但是当我重复时,图像会在我不需要的整个身体上重复: 我需要背景重复在x 100%然后400 px up或者什么,我希望我现在清晰:) – Brampage

+0

更好的是你创建单独的div,并设置背景图像,并设置该div的高度和宽度。 – Selvamani

回答

2

您可以尝试background-size

body{ 
    margin: 0px; 
    padding: 0px; 
    background-image: url(images/header.png), url(images/footer.png); 
    background-repeat: repeat-x, repeat-x; 
    background-size: auto, auto 500px; // here give to background images height 
    background-position: 0% 0%, 0% 100%; 


} 

更多信息有关background-sizeis here

+0

这是否适用于每个浏览器?感谢您的回答! – Brampage

+0

这是css3属性ie + 9 –

+1

多个背景只支持IE9 + –

0

我建议你创建单独的div并指定。

body { 
    margin: 0px; 
    padding: 0px; 
    background-image: url(images/header.png), ; 
    background-repeat: repeat-x; 
    background-height: 50px , 400px; 
    background-position: 0% 0%, 0% 100%; 
    div { 
     background-image: url(images/footer.png); 
     background-repeat: repeat; 
     background-height: 50px , 400px; 
    } 
}