2012-11-21 24 views
2

可能重複:
Multiple background-images and a background-color我可以在CSS元素上有兩個背景圖像和一個背景顏色嗎?

我可以有兩個背景圖片和背景顏色?

目前我只是有這樣的代碼,以達到預期的效果:

#myelement { 
    background: url("http://zbee.me/tz/bottom-right.png") no-repeat right bottom, 
    url("http://zbee.me/tz/top-left.png") no-repeat left top, 
    url("http://zbee.me/tz/bg.png"); 
} 

但我想用這樣的:

#myelement { 
    background: url("http://zbee.me/tz/bottom-right.png") no-repeat right bottom, 
    url("http://zbee.me/tz/top-left.png") no-repeat left top; 
    background-color: #35434E; 
} 

這可能嗎?

+0

我想你不需要支持舊瀏覽器? – user123444555621

回答

2

如果你正在尋找在同一時間有兩個圖像,他們將繼續這樣,那麼你可以看看這篇文章,解釋了你需要的東西:Can I have multiple background images using CSS?

不幸的是,你不能有這樣的組合,如果你想單獨操作背景,但是你可以重疊分層,就像每層都有自己的背景一樣。

你最好的拍攝將有一個部門內的兩個區,每個區都有自己的背景和位置,確保家長是相對的,孩子們絕對:

<div id="wrapper"> 
    <div id="bg1"></div> 
    <div id="bg2"></div> 
</div> 

CSS:

#wrapper{ 
position:relative; 
width:500px; 
height:500px; 
background: /* The bacground color you need */ 
} 

#bg1{ 
position:absolute; 
width: 250px; 
height:500px; 
right:0; 
background: /* The bacground you need and position */ 
} 

#bg2{ 
position:absolute; 
width: 250px; 
height:500px; 
left:0; 
background: /* The bacground you need and position */ 
} 
1

它的那樣簡單

#myelement { 
    background: url("http://zbee.me/tz/bottom-right.png") no-repeat right bottom, 
    url("http://zbee.me/tz/top-left.png") no-repeat left top, 
    #35434E; 
} 

background屬性爲composed of background-layers,最後一層可以是一種顏色。