html - 如何隐藏图像上的线性背景?

标签 html image css background

我正在寻找不覆盖图像的线性背景;我已经尝试过使用白色背景的 div,或者不使用背景标签,但显然行不通。

#heading:before {
    background: linear-gradient(#111111 0%, #123467 65%);
    content: ' ';
    display: block;
    height: 100%;
    left: 0;
    opacity: 0.6;
    position: absolute;
    top: 0;
    width: 100%;
    z-index: 1;
}
<div id="heading" >
  <img style="position:absolute;left:5%" src="images/gray_circle_logo.png" width="10%"/>
</div>

非常感谢 安德鲁

最佳答案

z-index: 1:after 伪元素定位在图像的前面。

要么删除 z-index,要么给图像一个更高的 z-index

移除了 z-index

#heading:before {
    background: linear-gradient(#111111 0%, #123467 65%);
    content: ' ';
    display: block;
    height: 100%;
    left: 0;
    opacity: 0.6;
    position: absolute;
    top: 0;
    width: 100%;
    
}
<div id="heading" >
  <img style="position:absolute;left:5%" src="images/gray_circle_logo.png" width="10%"/>
</div>

带有 z-index 的图像

#heading:before {
    background: linear-gradient(#111111 0%, #123467 65%);
    content: ' ';
    display: block;
    height: 100%;
    left: 0;
    opacity: 0.6;
    position: absolute;
    top: 0;
    width: 100%;
    z-index: 1;
}

#heading img {
  /* absolute positioning from inline styles */
  z-index: 2;
}
<div id="heading" >
  <img style="position:absolute;left:5%" src="images/gray_circle_logo.png" width="10%"/>
</div>

关于html - 如何隐藏图像上的线性背景?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50799436/

相关文章:

javascript - 如何使用 jQuery 对固定元素的位置进行动画处理

html - 图像上的响应式文本

css - 为什么重复 ID 在 HTML5 检查中会出错?

html - 将所有设备的保留页面居中 - CSS 和 HTML

javascript - 如何使用 jquery 或 javascript 隐藏 div?

c - 如何读取图像文件?

javascript - 用我的 HTML 编写的图像不可见

r - 为什么我在 Shiny 应用程序上的图像崩溃了?

html - CSS 边框图像不工作

html - 尺寸可变的CSS悬停图像裁剪