梯度IMG使用CSS标签 [英] Gradient over img tag using css
本文介绍了梯度IMG使用CSS标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要放置在一个℃的梯度; IMG>
标记。 标记的SRC
属性是角项目。例如:< IMG SRC = {{value.angitem.image}}>
我试图让CSS类:
.pickgradient {
背景:-webkit-梯度(线性,左上角,左下角,颜色停止(0%,RGBA(0,0,0,0)),彩站(100%,RGBA(0,0,0,0.65 )));
}
和
< IMG SRC = {{value.angitem.image}}类=pickgradient>
,但它不工作。我应该怎么办?
解决方案
用z-index:
您可以使用一个容器,把梯度容器上。然后使用负的z-index定位图片渐变背后
\r
\r\r
\r .pickgradient {\r
显示:inline-block的;\r
背景:-moz线性梯度(顶,RGBA(0,0,0,0)0%,RGBA(0,0,0,0.65)100%); / * FF3.6 + * /\r
背景:-webkit-梯度(线性,左上角,左下角,颜色停止(0%,RGBA(0,0,0,0.65)),彩站(100%,RGBA(0,0,0,0 ))); / *铬,Safari4 + * /\r
背景:-webkit线性梯度(顶,RGBA(0,0,0,0)0%,RGBA(0,0,0,0.65)100%); / * Chrome10 +,Safari5.1 + * /\r
背景:-o-线性梯度(顶,RGBA(0,0,0,0)0%,RGBA(0,0,0,0.65)100%); / *歌剧11.10+ * /\r
背景:-ms线性梯度(顶,RGBA(0,0,0,0)0%,RGBA(0,0,0,0.65)100%); / * IE10 + * /\r
背景:线性梯度(上下,RGBA(0,0,0,0)0%,RGBA(0,0,0,0.65)100%); / * * W3C /\r
过滤:进程id:DXImageTransform.Microsoft.gradient(startColorstr ='#a6000000',endColorstr =#00000000,GradientType = 0); / * * IE6-9 /\r
}\r
\r
IMG {\r
位置:相对;\r
的z-index:-1;\r
显示:块;\r
}
\r
< DIV CLASS =pickgradient>\r
&所述; IMG SRC =http://lorempixel.com/image_output/people-q-c-640-480-9.jpg/>\r
< / DIV>
\r
与伪元素:
至于评论,你也可以使用一个伪元素与梯度和绝对定位将在梯度图像
\r
\r\r
\r .pickgradient {\r
位置:相对;\r
显示:inline-block的;\r
}\r
.pickgradient:{后\r
内容:'';\r
位置:绝对的;\r
左:0;顶部:0;\r
宽度:100%;高度:100%;\r
显示:inline-block的;\r
背景:-moz线性梯度(顶,RGBA(0,0,0,0)0%,RGBA(0,0,0,0.65)100%); / * FF3.6 + * /\r
背景:-webkit-梯度(线性,左上角,左下角,颜色停止(0%,RGBA(0,0,0,0.65)),彩站(100%,RGBA(0,0,0,0 ))); / *铬,Safari4 + * /\r
背景:-webkit线性梯度(顶,RGBA(0,0,0,0)0%,RGBA(0,0,0,0.65)100%); / * Chrome10 +,Safari5.1 + * /\r
背景:-o-线性梯度(顶,RGBA(0,0,0,0)0%,RGBA(0,0,0,0.65)100%); / *歌剧11.10+ * /\r
背景:-ms线性梯度(顶,RGBA(0,0,0,0)0%,RGBA(0,0,0,0.65)100%); / * IE10 + * /\r
背景:线性梯度(上下,RGBA(0,0,0,0)0%,RGBA(0,0,0,0.65)100%); / * * W3C /\r
过滤:进程id:DXImageTransform.Microsoft.gradient(startColorstr ='#a6000000',endColorstr =#00000000,GradientType = 0); / * * IE6-9 /\r
}\r
\r
IMG {\r
显示:块;\r
}
\r
< DIV CLASS =pickgradient>\r
&所述; IMG SRC =http://lorempixel.com/image_output/people-q-c-640-480-9.jpg/>\r
< / DIV>
\r
I want to place a gradient over an <img>
tag. src
attribute of the tag is angular-item. For example:
<img src={{value.angitem.image}}>
I've tried to make css class:
.pickgradient {
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgba(0,0,0,0)), color-stop(100%,rgba(0,0,0,0.65)));
}
and
<img src={{value.angitem.image}} class="pickgradient ">
but it doesn't work. What should I do?
解决方案
With z-index :
You may use a container and put the gradient on that container. Then use a negative z-index to position image behind the gradient.
.pickgradient {
display:inline-block;
background: -moz-linear-gradient(top, rgba(0,0,0,0) 0%, rgba(0,0,0,0.65) 100%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgba(0,0,0,0.65)), color-stop(100%,rgba(0,0,0,0))); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(top, rgba(0,0,0,0) 0%,rgba(0,0,0,0.65) 100%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(top, rgba(0,0,0,0) 0%,rgba(0,0,0,0.65) 100%); /* Opera 11.10+ */
background: -ms-linear-gradient(top, rgba(0,0,0,0) 0%,rgba(0,0,0,0.65) 100%); /* IE10+ */
background: linear-gradient(to bottom, rgba(0,0,0,0) 0%,rgba(0,0,0,0.65) 100%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#a6000000', endColorstr='#00000000',GradientType=0 ); /* IE6-9 */
}
img{
position:relative;
z-index:-1;
display:block;
}
<div class="pickgradient">
<img src="http://lorempixel.com/image_output/people-q-c-640-480-9.jpg" />
</div>
With a pseudo element :
As commented, you can also use a pseudo element with the gradient and absolute positioning to put the gradient over the image :
.pickgradient{
position:relative;
display:inline-block;
}
.pickgradient:after {
content:'';
position:absolute;
left:0; top:0;
width:100%; height:100%;
display:inline-block;
background: -moz-linear-gradient(top, rgba(0,0,0,0) 0%, rgba(0,0,0,0.65) 100%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgba(0,0,0,0.65)), color-stop(100%,rgba(0,0,0,0))); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(top, rgba(0,0,0,0) 0%,rgba(0,0,0,0.65) 100%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(top, rgba(0,0,0,0) 0%,rgba(0,0,0,0.65) 100%); /* Opera 11.10+ */
background: -ms-linear-gradient(top, rgba(0,0,0,0) 0%,rgba(0,0,0,0.65) 100%); /* IE10+ */
background: linear-gradient(to bottom, rgba(0,0,0,0) 0%,rgba(0,0,0,0.65) 100%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#a6000000', endColorstr='#00000000',GradientType=0 ); /* IE6-9 */
}
img{
display:block;
}
<div class="pickgradient">
<img src="http://lorempixel.com/image_output/people-q-c-640-480-9.jpg" />
</div>
这篇关于梯度IMG使用CSS标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文