【问题标题】:I would like to have a background-image with a 'fade out effect'. CSS3我想要一个具有“淡出效果”的背景图像。 CSS3
【发布时间】:2013-04-09 04:18:26
【问题描述】:

是否可以实现从图片中心到图片左侧的图片淡出透明效果

我尝试了以下方法,但没有得到任何结果

#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;

}

【问题讨论】:

  • 嗯,不,如果我想这样做。我只是将图像做成 PNG,我想学习如何使用新的 CSS3 函数

标签: html css gradient


【解决方案1】:

一种解决方案是使用模糊的嵌入框阴影 (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;
}



如果要使用渐变,可以使用:before获取渐变覆盖背景图片,否则看不到渐变。

以下是如何实现此目的的示例:
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);
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-15
    • 2020-04-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多