Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/assembly/5.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
CSS在图像元素上显示div背景_Css_Background_Gradient_Overlap - Fatal编程技术网

CSS在图像元素上显示div背景

CSS在图像元素上显示div背景,css,background,gradient,overlap,Css,Background,Gradient,Overlap,我有这个HTML: <div class="container"> <img class="image" src="someUrl"> <div class="gradientDown"></div> <div class="gradientUp"></div> </div> 我想梯度div重叠在图像上,图像明显地在它们之间徘徊。我尝试过调整z索引、位置和显示,但似乎找不到方法。它们总是

我有这个HTML:

<div class="container">
    <img class="image" src="someUrl">
    <div class="gradientDown"></div>
    <div class="gradientUp"></div>
</div>
我想梯度div重叠在图像上,图像明显地在它们之间徘徊。我尝试过调整z索引、位置和显示,但似乎找不到方法。它们总是出现在图像下方。

*现在定义您的
z-index
属性*

像这样

img{
    position:relative;
    z-index:1;  
}

<div class="container">
    <img class="image" src="someUrl">
    <div class="gradientDown"></div>
    <div class="gradientUp"></div>
</div>
有关

*的更多信息,现在定义您的
img
z-index
属性*

<div class="container">
    <img class="image" src="someUrl">
    <div class="gradientDown"></div>
    <div class="gradientUp"></div>
</div>
像这样

img{
    position:relative;
    z-index:1;  
}

<div class="container">
    <img class="image" src="someUrl">
    <div class="gradientDown"></div>
    <div class="gradientUp"></div>
</div>

有关

z-index的详细信息对于具有position:static(默认值)的元素不起作用。如果你给你的img一些定位,z-index应该会起作用。

z-index对位置为static(默认)的元素不起作用。如果你给你的img一些定位,z索引应该会起作用。


<div class="container">
    <img class="image" src="someUrl">
    <div class="gradientDown"></div>
    <div class="gradientUp"></div>
</div>
<html>
<head>
    <style>
        div{
            position:  relative;
        }
        .container {
            position:relative;
            width:100%;
            height:100%;
            padding-top:70.5px;
        }

        .gradientDown {
            position:relative;
            margin-top: -300px;
            top:0;
            width:100%;
            height:100px;
            background:linear-gradient(to bottom, rgba(40,40,40,1), rgba(40,40,40,0));
        }

        .gradientUp {
            position: relative;
            bottom:0;
            width:100%;
            height:100px;
            background:linear-gradient(to top, rgba(40,40,40,1), rgba(40,40,40,0));
        }
    </style>
</head>
<body>
<div class="container">
    <div><img class="image" src="someurl"></div>
    <div class="gradientDown"></div>
    <div class="gradientUp"></div>
</div>
</body>
</html>
div{ 位置:相对位置; } .集装箱{ 位置:相对位置; 宽度:100%; 身高:100%; 垫面:70.5px; } .梯度下降{ 位置:相对位置; 利润上限:-300px; 排名:0; 宽度:100%; 高度:100px; 背景:线性梯度(至底部,rgba(40,40,40,1),rgba(40,40,40,0)); } .梯度上升{ 位置:相对位置; 底部:0; 宽度:100%; 高度:100px; 背景:线性梯度(到顶部,rgba(40,40,40,1),rgba(40,40,40,0)); }

div{
位置:相对位置;
}
.集装箱{
位置:相对位置;
宽度:100%;
身高:100%;
垫面:70.5px;
}
.梯度下降{
位置:相对位置;
利润上限:-300px;
排名:0;
宽度:100%;
高度:100px;
背景:线性梯度(至底部,rgba(40,40,40,1),rgba(40,40,40,0));
}
.梯度上升{
位置:相对位置;
底部:0;
宽度:100%;
高度:100px;
背景:线性梯度(到顶部,rgba(40,40,40,1),rgba(40,40,40,0));
}

Fiddle你拥有的东西:。你对它的外观有印象吗?我不了解你在找什么。。也许你的浏览器没有更新?你所拥有的东西太多了:。你对它的外观有印象吗?我不了解你在找什么。。也许你的浏览器没有更新?