CSS 带有背景图像的白色到透明渐变
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6397712/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
White to transparent gradient with background image
提问by Craig
I need to apply a white to transparent gradient which covers about a 1/4 of the top of the page and a background image visible for the rest of the page.
我需要应用一个白色到透明的渐变,它覆盖页面顶部的大约 1/4 和页面其余部分可见的背景图像。
Im looking to achieve a seamless blend from a gradient to a textured image and to do this in CSS3.
我希望实现从渐变到纹理图像的无缝混合,并在 CSS3 中做到这一点。
回答by MikeM
I recommend Ultimate CSS Gradient Generator - ColorZilla.com
我推荐Ultimate CSS Gradient Generator - ColorZilla.com
It's a well designed tool and there's a white to transparent preset.
这是一个设计精良的工具,有一个白色到透明的预设。
The CSS code that it generates for a white to transparent gradient is this:
它为白色到透明渐变生成的 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 */
回答by Mikhail Shabrikov
I prefer to use another tool for gradients generation - EnjoyCSS. It also allows to generate other CSS features like background, shadows, transitions etc.
我更喜欢使用另一个工具来生成渐变——EnjoyCSS。它还允许生成其他 CSS 功能,如背景、阴影、过渡等。
White to transparent gradient generated with this tool:
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;