Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Image CSS中从顶部0%到底部100%的透明(不透明度)图像_Image_Css_Opacity_Css Shapes - Fatal编程技术网

Image CSS中从顶部0%到底部100%的透明(不透明度)图像

Image CSS中从顶部0%到底部100%的透明(不透明度)图像,image,css,opacity,css-shapes,Image,Css,Opacity,Css Shapes,有可能吗?就在CSS中,就像这张图片,所以我的意思是,如果我把标签放在背景图片上,我需要它从上到下都是透明的 我想创建类似下图的内容: I供您使用。您必须将渐变与rgba一起使用。并非所有浏览器都支持此操作,因此您可能希望改为操作图像。然而,这是在CSS中实现这一点的唯一方法 代码如下: HTML: <html> <head> </head> <body> <img src="http://upload

有可能吗?就在CSS中,就像这张图片,所以我的意思是,如果我把
标签放在背景图片上,我需要它从上到下都是透明的

我想创建类似下图的内容:

I供您使用。您必须将渐变与rgba一起使用。并非所有浏览器都支持此操作,因此您可能希望改为操作图像。然而,这是在CSS中实现这一点的唯一方法

代码如下:

HTML:

<html>
    <head>
    </head>
    <body>
        <img src="http://upload.wikimedia.org/wikipedia/meta/6/6d/Wikipedia_wordmark_1x.png" />
        <div class="whatever"></div>
    </body>
</html>
body {
    margin:0px;
}

img {
    height:30px;
    position:relative;
}

.whatever {
    background-image: -webkit-gradient(
        linear,
        left top,
        left bottom,
        color-stop(0, #ff00ff),
        color-stop(1, rgba(0,0,0,0))
    );
    background-image: -o-linear-gradient(bottom, #ff00ff 0%, rgba(0,0,0,0) 100%);
    background-image: -moz-linear-gradient(bottom, #ff00ff 0%, rgba(0,0,0,0) 100%);
    background-image: -webkit-linear-gradient(bottom, #ff00ff 0%, rgba(0,0,0,0) 100%);
    background-image: -ms-linear-gradient(bottom, #ff00ff 0%, rgba(0,0,0,0) 100%);
    background-image: linear-gradient(to bottom, #ff00ff 0%, rgba(0,0,0,0) 100%);
    height:30px;
    position:relative;
    width:100px;
    top:-34px;
}
div {
  -webkit-mask-size: 300px 200px;
  -webkit-mask-image: -webkit-gradient(linear, center top, center bottom, 
  color-stop(0.00,  rgba(0,0,0,0)),
  color-stop(1.00,  rgba(0,0,0,1)));
}

您应该使用
background
CSS属性,该属性带有
线性渐变
值,该值由您根据自己的要求设置

CSS
检查这个我认为根本不可能精确地复制它(特别是如果img的顶部实际上是透明的)。如果您只需要将“透明度”从白色设置为图像的透明度,则会更容易一些

HTML

<div class="wrapper">
    <div class="imgwrap">
    <img src="http://lorempixel.com/output/nature-q-c-200-200-2.jpg" alt=""/>
    </div>
</div>     

正如其他答案所述:在CSS中,使图像从上到下透明是不可能的

但是

如果您有纯色背景色(或类似颜色),则可以使用CSS3插入框阴影模拟该透明度。
对于图像白色覆盖和半透明黑色矩形。在下面的演示中,我使用伪元素最小化HTML标记

输出:

HTML:


事实上,您可以在webkit中执行此操作!Mozilla允许SVG掩码,但我不想讨论这个问题。IE中的零支持

演示:

HTML:

<html>
    <head>
    </head>
    <body>
        <img src="http://upload.wikimedia.org/wikipedia/meta/6/6d/Wikipedia_wordmark_1x.png" />
        <div class="whatever"></div>
    </body>
</html>
body {
    margin:0px;
}

img {
    height:30px;
    position:relative;
}

.whatever {
    background-image: -webkit-gradient(
        linear,
        left top,
        left bottom,
        color-stop(0, #ff00ff),
        color-stop(1, rgba(0,0,0,0))
    );
    background-image: -o-linear-gradient(bottom, #ff00ff 0%, rgba(0,0,0,0) 100%);
    background-image: -moz-linear-gradient(bottom, #ff00ff 0%, rgba(0,0,0,0) 100%);
    background-image: -webkit-linear-gradient(bottom, #ff00ff 0%, rgba(0,0,0,0) 100%);
    background-image: -ms-linear-gradient(bottom, #ff00ff 0%, rgba(0,0,0,0) 100%);
    background-image: linear-gradient(to bottom, #ff00ff 0%, rgba(0,0,0,0) 100%);
    height:30px;
    position:relative;
    width:100px;
    top:-34px;
}
div {
  -webkit-mask-size: 300px 200px;
  -webkit-mask-image: -webkit-gradient(linear, center top, center bottom, 
  color-stop(0.00,  rgba(0,0,0,0)),
  color-stop(1.00,  rgba(0,0,0,1)));
}

CSS:

<html>
    <head>
    </head>
    <body>
        <img src="http://upload.wikimedia.org/wikipedia/meta/6/6d/Wikipedia_wordmark_1x.png" />
        <div class="whatever"></div>
    </body>
</html>
body {
    margin:0px;
}

img {
    height:30px;
    position:relative;
}

.whatever {
    background-image: -webkit-gradient(
        linear,
        left top,
        left bottom,
        color-stop(0, #ff00ff),
        color-stop(1, rgba(0,0,0,0))
    );
    background-image: -o-linear-gradient(bottom, #ff00ff 0%, rgba(0,0,0,0) 100%);
    background-image: -moz-linear-gradient(bottom, #ff00ff 0%, rgba(0,0,0,0) 100%);
    background-image: -webkit-linear-gradient(bottom, #ff00ff 0%, rgba(0,0,0,0) 100%);
    background-image: -ms-linear-gradient(bottom, #ff00ff 0%, rgba(0,0,0,0) 100%);
    background-image: linear-gradient(to bottom, #ff00ff 0%, rgba(0,0,0,0) 100%);
    height:30px;
    position:relative;
    width:100px;
    top:-34px;
}
div {
  -webkit-mask-size: 300px 200px;
  -webkit-mask-image: -webkit-gradient(linear, center top, center bottom, 
  color-stop(0.00,  rgba(0,0,0,0)),
  color-stop(1.00,  rgba(0,0,0,1)));
}

参考:

在图像上覆盖一个渐变div,并带有绝对位置和z索引:

CSS

HTML



CSS AFAIK不太可能。事实上,我认为完全不可能重现这种情况(特别是如果img的顶部实际上是透明的)…至少在没有大量不必要的额外HTML和CSS的情况下是不可能的。有时候图片是最好的方式。好的,谢谢你的回复。我会尝试用不同的方式来做如果你只需要将“透明度”从白色变成图像…这会更容易一点…那会吗?相同的区别。一开始就不透明的东西不能透明。