bal*_*ker 12 css transparency linear-gradients css3
有没有办法在图像的-webkit-linear-gradient左侧和右侧为CSS中的图像添加透明度?
我有一个图像,我想添加透明度 - 纯CSS - 避免使用像Photoshop,Gimp等任何图像编辑器.我试图使用-webkit-linear-gradient但它使用rgba()函数来定义色块.
所以这个片段
height: 200px;
background: -webkit-linear-gradient(left, rgba(255,0,0,0), rgba(255,0,0,1));
Run Code Online (Sandbox Code Playgroud)
做这个:

在此示例中,rgba()中的最后一个参数定义颜色的透明度.到现在为止还挺好.如果我把right在-webkit-linear-gradient图像上方会显示相反.(你不说?!)
我想以某种方式将两者合并,并创建一个两边透明的渐变.只有不用渐变.带图像.
我也尝试过box-shadow,radial-gradient但我无法弄明白.
有没有办法只使用CSS在图像的左侧和右侧添加透明度?
例:

jbu*_*483 20
您可以使用包装器div然后使用颜色停止:
div {
position: relative;
display: inline-block;
}
div:before {
content: "";
top: 0;
left: 0;
position: absolute;
height: 100%;
width: 100%;
background: -moz-linear-gradient(left, rgba(255, 255, 255, 1) 0%, rgba(255, 255, 255, 0) 49%, rgba(255, 255, 255, 1) 100%);
/* FF3.6+ */
background: -webkit-gradient(linear, left top, right top, color-stop(0%, rgba(255, 255, 255, 1)), color-stop(49%, rgba(255, 255, 255, 0)), color-stop(100%, rgba(255, 255, 255, 1)));
/* Chrome,Safari4+ */
background: -webkit-linear-gradient(left, rgba(255, 255, 255, 1) 0%, rgba(255, 255, 255, 0) 49%, rgba(255, 255, 255, 1) 100%);
/* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(left, rgba(255, 255, 255, 1) 0%, rgba(255, 255, 255, 0) 49%, rgba(255, 255, 255, 1) 100%);
/* Opera 11.10+ */
background: -ms-linear-gradient(left, rgba(255, 255, 255, 1) 0%, rgba(255, 255, 255, 0) 49%, rgba(255, 255, 255, 1) 100%);
/* IE10+ */
background: linear-gradient(to right, rgba(255, 255, 255, 1) 0%, rgba(255, 255, 255, 0) 49%, rgba(255, 255, 255, 1) 100%);
/* W3C */
filter: progid: DXImageTransform.Microsoft.gradient(startColorstr='#ffffff', endColorstr='#ffffff', GradientType=1);
/* IE6-9 */
}Run Code Online (Sandbox Code Playgroud)
<div>
<img src="http://placekitten.com/g/300/300" alt="" />
</div>Run Code Online (Sandbox Code Playgroud)
资源
迟到的答案,但其他人可以利用它。您可以仅用一行在两侧放置一个透明的渐变:
background: linear-gradient(to right, rgba(0, 0, 0, 0), rgba(255, 0, 0, 1), rgba(0, 0, 0, 0))
Run Code Online (Sandbox Code Playgroud)