2013-08-05 293 views
0

我有一个div这得到了一个背景颜色和图像(具有透明背景)CSS背景图片和默认背景?

我需要默认(白色)上在div不同的背景颜色与另一种颜色作为背景为透明图像。

我怎样才能解决这个问题?

我有现在这样设置背景:

background: rgb(0,0,255) url(images/trans.png); 
background-repeat: repeat-x; 

所以重复停止时,我需要另一种背景颜色。

我想过一个渐变作为背景,但我不知道如何与一个固定的像素POS过渡做到这一点(与%作品)

here i got the JSFiddle

+0

提供一个的jsfiddle利nk和你的代码。 – Nitesh

回答

3

你可以写像素而不是百分比: UPDATE:与固体颜色接近例如:

background: url(https://cdn.sstatic.net/stackoverflow/img/apple-touch-icon.png) repeat-x 0 0, -moz-linear-gradient(top, rgb(0,0,255) 0px, rgb(0,0,255) 154px, rgba(255,255,255,0.5) 155px, rgba(255,255,255,0.5) 300px); 

background: url(https://cdn.sstatic.net/stackoverflow/img/apple-touch-icon.png) repeat-x 0 0, -webkit-gradient(linear, left top, left bottom, color-stop(0px,rgb(0,0,255)),color-stop(154px,rgb(0,0,255)),color-stop(155px,rgba(255,255,255,0.5)), color-stop(300px,rgba(255,255,255,0.5))); 

background: url(https://cdn.sstatic.net/stackoverflow/img/apple-touch-icon.png) repeat-x 0 0, -webkit-linear-gradient(top, rgb(0,0,255) 0px,rgb(0,0,255) 155px,rgba(255,255,255,0.5) 155px,rgba(255,255,255,0.5) 300px); 

background: url(https://cdn.sstatic.net/stackoverflow/img/apple-touch-icon.png) repeat-x 0 0, -o-linear-gradient(top, rgb(0,0,255) 0px,rgb(0,0,255) 154px,rgba(255,255,255,0.5) 155px,rgba(255,255,255,0.5) 300px); 

background: url(https://cdn.sstatic.net/stackoverflow/img/apple-touch-icon.png) repeat-x 0 0, -ms-linear-gradient(top, rgb(0,0,255) 0px,rgb(0,0,255) 154px,rgba(255,255,255,0.5) 155px,rgba(255,255,255,0.5) 300px); 

background: url(https://cdn.sstatic.net/stackoverflow/img/apple-touch-icon.png) repeat-x 0 0, linear-gradient(to bottom, rgb(0,0,255) 0px,rgb(0,0,255) 154px,rgba(255,255,255,0.5) 155px,rgba(255,255,255,0.5) 300px); 

http://jsfiddle.net/pBVsD/12/

+0

我并不是想让渐变变得透明,它的图像是透明的,而且通过图像看到渐变,看到我的小提琴 – lumo

+0

那么,这只是一个例子。您可以使用纯色渐变。问题是,你可以使用像素来指定你的渐变尺寸 – Wood

+0

我明白,但每次我尝试添加渐变时,图像会丢失。如果你能为我提供一个修理我的小提琴,那将是非常棒的。尝试多个(将添加我的一个尝试作为小提琴上面) – lumo