I would like to have a background-image with a 'fade out effect'. CSS3

懵懂的女人 提交于 2019-12-01 23:12:04

问题


Is it possible to achieve fade out transparent effect on an image from the center of an image to the left of the image

I have tried the below and i get no results

#content {
display: block;
width: 960px;
margin: auto;
margin-top: 48px;
background-image: url(../images/feature-image-wild-horse.jpg),    -moz-linear-gradient(left, #444444, #999999); /* FF3.6+ */
overflow: hidden;

}


回答1:


One solution would be to use a blurred inset box shadow (https://developer.mozilla.org/en/docs/CSS/box-shadow):

http://jsfiddle.net/n1ck/NkHdh/4/

#content {
    width:350px;
    height:350px;
    background-image: url(http://placekitten.com/350/350);
    -moz-box-shadow: inset 70px 0px 50px -10px white;
    -webkit-box-shadow: inset 70px 0px 50px -10px white;
     box-shadow:inset 70px 0px 50px -10px white;
}



If you want to use a gradient, you can use :before to get the gradient to overlay the background image, otherwise the gradient won't be seen.

Here's an example of how you can achieve this:
http://jsfiddle.net/n1ck/brqcu/2/

#content {
    width:350px;
    height:350px;
    background-image: url(http://placekitten.com/350/350);
}

#content:before {
    width:350px;
    height:350px;
    content:'';
    display:block;
    background: -moz-linear-gradient(left, rgba(255, 255, 255, 1) 0%, rgba(255, 255, 255, 0) 100%);
    background: -webkit-gradient(linear, left top, right top, color-stop(0%, rgba(255, 255, 255, 1)), color-stop(100%, rgba(255, 255, 255, 0)));
    background: -webkit-linear-gradient(left, rgba(255, 255, 255, 1) 0%, rgba(255, 255, 255, 0) 100%);
    background: -o-linear-gradient(left, rgba(255, 255, 255, 1) 0%, rgba(255, 255, 255, 0) 100%);
    background: -ms-linear-gradient(left, rgba(255, 255, 255, 1) 0%, rgba(255, 255, 255, 0) 100%);
    background: linear-gradient(to right, rgba(255, 255, 255, 1) 0%, rgba(255, 255, 255, 0) 100%);
    filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffffff', endColorstr='#00ffffff', GradientType=1);
}


来源:https://stackoverflow.com/questions/15893217/i-would-like-to-have-a-background-image-with-a-fade-out-effect-css3

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