我有一个div,它有背景颜色和图像(透明背景)
默认情况下我需要在div上使用不同的背景颜色(白色),而另一种颜色作为透明图像的背景颜色。
我该如何解决这个问题?
我现在已经设置了这样的背景:
background: rgb(0,0,255) url(images/trans.png);
background-repeat: repeat-x;
因此,当重复停止时,我需要另一种背景颜色。
我想过渐变作为背景,但我不知道如何通过固定像素位置的过渡(使用%)
答案 0 :(得分:3)
您可以写入像素而不是百分比: 更新:更接近纯色的例子:
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);