【问题标题】:I want overlay on image css我想叠加在图像 css 上
【发布时间】:2021-06-16 13:23:15
【问题描述】:

我想要在图片顶部不可点击的叠加层

评论区的codepen链接

html:

<img src="https://www.codeproject.com/KB/GDI-plus/ImageProcessing2/img.jpg" />

css:

img{
  width:100px;
  height:100px;
  cursor: not-allowed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(0,0,0,0.5);
  z-index: 1000;

}

图像顶部带有灰色不透明度

类似的东西 https://prnt.sc/10pm4zm

【问题讨论】:

标签: javascript css css-selectors overlay opacity


【解决方案1】:
<div class="container">
  <img src="https://www.codeproject.com/KB/GDI-plus/ImageProcessing2/img.jpg" />
  <div class="overlay"></div>
</div>

而css是

img {
  width: 100px;
  height: 100px;
}
.container {
  width: 100px;
  height: 100px;
  position: relative;
  pointer-events: none;
  }
.overlay {
  position: absolute;
  top: 0;
  left: 0;
  height: 100%;
  width: 100%;
  background: rgba( 0, 0, 0, 0.5 );
}

【讨论】:

【解决方案2】:

您可以在标签后添加另一个 div。并给它CSS如下

img{
  width:100px;
  height:100px;
  
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(0,0,0,0.5);
  

}
div{
  position:absolute;
  width:50px;
  height:30px;
  cursor: not-allowed;
  top: 80px;
  left: 10px;
  right: 0;
  bottom: 0;
  background-color: grey;
  z-index: 1000;
  opacity: 0.5;
}
<img src="https://www.codeproject.com/KB/GDI-plus/ImageProcessing2/img.jpg" />
<div></div>

此外,您可以相应地调整不透明度和覆盖不可点击 div 的大小

【讨论】:

  • 谢谢你的回答,你能帮我填充底部的div覆盖图像codepen.io/ranjan-raj-shrestha/pen/yLVdjLx
  • 请清除,您希望底部 div 覆盖或覆盖您的图像?
  • 好吧,去掉
    标签。然后底部的

    标签将覆盖图像

  • 根据以下给出的源代码:codepen.io/ranjan-raj-shrestha/pen/yLVdjLx 解决方案有效。您可以将 prnt.sc/10po9jx 的代码发送给我,以便我查看
猜你喜欢
相关资源
最近更新 更多
热门标签