Fade image to transparent like a gradient

匿名 (未验证) 提交于 2019-12-03 01:58:03

问题:

I would like to have an image (a background image) to fade to transparent so that content behind it can actually be seen (barely, thanks to transparency).

I can achieve it obviously with a PNG image, but I need to ask to my graphic designer to change the image every time I want to change the start => stop transparency points (maybe I want more color or maybe I want less color and more transparency).

Are there any chance I can achieve the same effect with CSS3? I tried applying a gradient to transparent on a jpg (and a png) but I can't see through it unless the PNG has already transparency (and basically the gradient) already done (which makes the css gradient useless).

Any suggestion? I'm digging hard through the web but seems like I'm not using the right keyword or maybe it's not possible.

Update 1:

Code says more than a lot of words, I would like to do something like this (but the syntax is obviously wrong):

background: linear-gradient(to bottom, rgba(url('splash_bottom3.png'), 0.0), rgba(url('splash_bottom3.png'), 1.0)); 

回答1:

Complete rewrite of my previous answer, because I seemingly and totally misunderstood the question.

If you want this:

You can do this:

   
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi sit amet porttitor massa. Morbi eget tortor congue, aliquet odio a, viverra metus. Ut cursus enim eu felis sollicitudin, vitae eleifend urna lobortis. Mauris elementum erat non facilisis cursus. Fusce sit amet lacus dictum, porta libero sed, euismod tellus. Aenean erat augue, sodales sed gravida ac, imperdiet ac augue. Ut condimentum dictum mauris. Donec tincidunt enim a massa molestie, vel volutpat massa dictum. Donec semper odio vitae adipiscing lacinia.

Update 1

If you want to do this in other browsers, it won't be as easy. Firefox needs an SVG and IE needs a whole slew of work arounds.



回答2:

If you just want to fade to the background color (white, in this case) see the working example here:

http://jsfiddle.net/yw9v7zm5/

.css for the image container div uses:

background: -moz-linear-gradient(top,  rgba(255,255,255,0) 0%, rgba(255,255,255,1) 80%); background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgba(255,255,255,0)), color-stop(80%,rgba(255,255,255,1))); background: -webkit-linear-gradient(top,  rgba(255,255,255,0) 0%,rgba(255,255,255,1) 80%); background: -o-linear-gradient(top,  rgba(255,255,255,0) 0%,rgba(255,255,255,1) 80%); background: -ms-linear-gradient(top,  rgba(255,255,255,0) 0%,rgba(255,255,255,1) 80%); background: linear-gradient(to bottom,  rgba(255,255,255,0) 0%,rgba(255,255,255,1) 80%); filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#00ffffff', endColorstr='#ffffff',GradientType=0 ); 


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!