用css和html在另一个图像上显示渐变图像



我想在另一个图像上显示渐变图像,但渐变图像没有显示在另一图像上。我的代码如下:

<style>
.splash-gradient
{
background-image: url('images/gradient.png');
background-position: left;
background-repeat: repeat-y;
float: right;
height: 300px;
width: 362px;
}
</style>
<div class="col-md-6"> <img src="images1.jpg" /></div>
 <div id="gradient-background" class="splash-gradient"></div>

避免仅出于样式目的使用空标记。你可以在现有的标记中添加一个类

<div class="col-md-6 splash-gradient"> 
  <img src="images1.jpg" />
</div>

然后使用这种样式:

.splash-gradient {
    position: relative;
}
.splash-gradient:before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    background: url('images/gradient.png') top left repeat-y;
    height: 300px;
    width: 362px;   
}

梯度被插入到:before伪元素上,并且由于在position: absolute中,它与图像重叠(当然可以随意调整宽度和高度)

最新更新