白色到透明的渐变与背景图片合成

35

我需要应用一个从白色到透明的渐变,覆盖页面顶部约1/4的位置,并使背景图片在整个页面中可见。

我希望在CSS3中实现从渐变到纹理图像的无缝混合。

2个回答

55

我推荐使用Ultimate CSS Gradient Generator - ColorZilla.com 这个工具。

它是一个设计良好的工具,并且有一个白色到透明的预设。

css gradient generator

生成的白色到透明渐变的CSS代码如下:

background: -moz-linear-gradient(top, rgba(255,255,255,1) 0%, rgba(255,255,255,0) 100%); /* FF3.6-15 */
background: -webkit-linear-gradient(top, rgba(255,255,255,1) 0%,rgba(255,255,255,0) 100%); /* Chrome10-25,Safari5.1-6 */
background: linear-gradient(to bottom, rgba(255,255,255,1) 0%,rgba(255,255,255,0) 100%); /* W3C, IE10+, FF16+, Chrome26+, Opera12+, Safari7+ */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#ffffff', endColorstr='#00ffffff',GradientType=0 ); /* IE6-9 */

2
Mike,你五年前的回答刚刚为我节省了数小时的时间,谢谢你。 - ColinMcDermott
很棒的答案,刚刚更新并包含了生成的代码。或者您可以点击此永久链接查看:http://colorzilla.com/gradient-editor/#ffffff+0,ffffff+100&1+0,0+100;White+to+Transparent - user9903
非常感谢。我已经寻找了两天。我尝试了Stackoverflow和网络上找到的所有方法,但这是唯一对我有效的答案。 - Ali

5

我更喜欢使用另一种生成渐变的工具 - EnjoyCSS。它还可以生成其他 CSS 特性,如背景、阴影、过渡等。

enter image description here 使用这个工具生成的白色到透明的渐变:

background-image: -webkit-linear-gradient(-90deg, rgba(255,255,255,0) 0, rgba(255,255,255,1) 100%);
background-image: -moz-linear-gradient(180deg, rgba(255,255,255,0) 0, rgba(255,255,255,1) 100%);
background-image: linear-gradient(180deg, rgba(255,255,255,0) 0, rgba(255,255,255,1) 100%);
background-position: 50% 50%;
-webkit-background-origin: padding-box;
background-origin: padding-box;
-webkit-background-clip: border-box;
background-clip: border-box;
-webkit-background-size: auto auto;
background-size: auto auto;

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接