2014-05-12 68 views
1

使用CSS3,您可以使用多個背景圖像。CSS3多背景垂直對齊

比方說,我有一個尺寸爲div {width:100px; height:200px;}的DIV容器。

我有4 100/50px背景圖像,我想對齊這些垂直,使整個DIV充滿了這4個背景從上到下。

這可能嗎?

回答

3

您可以在後臺多個圖像在CSS3 http://caniuse.com/#feat=multibackgrounds

http://jsfiddle.net/79TyM/

#container { 
    width:200px; 
    height:200px; 
    background: 
     url(http://placekitten.com/100/100) left top no-repeat, 
     url(http://placekitten.com/g/100/100) right top no-repeat, 
     url(http://placekitten.com/g/100/100) left bottom no-repeat,  
     url(http://placekitten.com/100/100) right bottom no-repeat; 
} 

OP想要的背景堆疊,而不是在一個正方形。更新小提琴:http://jsfiddle.net/79TyM/1/

#container { 
    width:100px; 
    height:400px; 
    background: 
     url(http://placekitten.com/100/100) left top no-repeat, 
     url(http://placekitten.com/g/100/100) left 100px no-repeat, 
     url(http://placekitten.com/g/100/100) left 200px no-repeat,  
     url(http://placekitten.com/100/100) left 300px no-repeat; 
} 
+0

這是接近的,但我想在對方的所有圖像。那可能嗎? –

+0

當然http://jsfiddle.net/79TyM/1/ –

+1

非常感謝你這麼多 –

0

是的,有可能使用background: url(...)財產。一個很好的解釋可以找到here

基本上,這是語法:

... 
background: 
    url(number.png) 600px 10px no-repeat, /* On top, like z-index: 4; */ 
    url(thingy.png) 10px 10px no-repeat, /*   like z-index: 3; */ 
    url(Paper-4.png);      /* On bottom, like z-index: 1; */ 
... 
+0

我以前見過那個例子,但是我想弄清楚的是如何在沒有進一步重複的情況下獲取所有背景。 –

+0

不重複應該照顧那個。 – Callistino