我如何使用CSS3渐变为我的背景颜色,然后应用背景图像应用某种轻透明纹理?


当前回答

对于我的响应式设计,我的下拉框在框的右侧(垂直手风琴),接受百分比作为位置。最初,下箭头是“位置:绝对;右:13 px;”。在97%的定位下,它的工作原理如下:

> background: #ffffff;
> background-image: url(PATH-TO-arrow_down.png); /*fall back - IE */
> background-position: 97% center; /*fall back - IE */
> background-repeat: no-repeat; /*fall back - IE */
> background-image: url(PATH-TO-arrow_down.png)  no-repeat  97%  center;  
> background: url(PATH-TO-arrow_down.png) no-repeat 97% center,  -moz-linear-gradient(top, #ffffff 1%, #eaeaea 100%); 
> background: url(PATH-TO-arrow_down.png) no-repeat 97% center,  -webkit-gradient(linear, left top, left bottom, color-stop(1%,#ffffff), color-stop(100%,#eaeaea)); 
> background: url(PATH-TO-arrow_down.png) no-repeat 97% center,  -webkit-linear-gradient(top, #ffffff 1%,#eaeaea 100%); 
> background: url(PATH-TO-arrow_down.png) no-repeat 97% center,  -o-linear-gradient(top, #ffffff 1%,#eaeaea 100%);<br />
> filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#ffffff', endColorstr='#eaeaea',GradientType=0 ); 

附注:对不起,我不知道如何处理滤镜。

其他回答

如果你必须在IE 9 (HTML 5 & HTML 4.01 Strict)中让渐变和背景图像一起工作,添加以下属性声明到你的css类中,它应该可以做到:

filter: progid:DXImageTransform.Microsoft.gradient(GradientType=0, startColorstr='#000000', endColorstr='#ff00ff'), progid:DXImageTransform.Microsoft.AlphaImageLoader(src='[IMAGE_URL]', sizingMethod='crop');

注意,您使用了filter属性,并且progid有两个实例:[val],在用分号关闭属性值之前,用逗号分隔。这是小提琴。还要注意,当你看小提琴时,梯度延伸到圆角之外。我没有解决其他不使用圆角。还要注意,当在src [IMAGE_URL]属性中使用相对路径时,该路径是相对于文档页面而不是css文件(参见源代码)。

这篇文章(http://coding.smashingmagazine.com/2010/04/28/css3-solutions-for-internet-explorer/)引导我找到了这个解决方案。它对特定于ie的CSS3非常有帮助。

我的解决方案:

background-image: url(IMAGE_URL); /* fallback */

background-image: linear-gradient(to bottom, rgba(0,0,0,0.7) 0%,rgba(0,0,0,0.7) 100%), url(IMAGE_URL);

作为一个可靠的方法,你可以只做一个背景图像是500x5像素,在你的css使用:

background-img:url(bg.jpg) fixed repeat-x;
background:#<xxxxxx>;

其中xxxxxx对应与最终渐变颜色相匹配的颜色。

你也可以把它固定在屏幕的底部,让它与初始渐变颜色相匹配。

如果你想要一个在中心只有一个背景图像的渐变,你可以用一行代码做到,像这样:

body {
  background:  url(logo.png) no-repeat fixed center center, linear-gradient(#00467f, #a5cc82) fixed;
}

使用背景-混合模式和rgba混合背景图像和颜色

这是你需要的:

.myblendedbg {
  background-image: url("some_image.png");
  background-color: rgba(0, 0, 0, 0.85); /* use rgba for fine adjustments */
  background-blend-mode: multiply;
}

如果你调整rgba颜色值的alpha值(在这个例子中是。85),你可以控制透明度。

此外,背景-混合模式还有其他值,你可以用它来获得一些真正有创意的结果。

注:background-blend-mode: color;在火狐浏览器上不能运行,而multiply在所有现代浏览器上都可以运行