html - 如何在图像上方创建一个图层(不透明)?

标签 html css css-shapes

<分区>

我们如何创建下图所示的效果?

What I need to create

最佳答案

可以使用 :before:after 伪元素创建此叠加层:

HTML:

<div class="image-holder">
  <img src="https://i.imgur.com/waDgcnc.jpg" />
</div>

必要的 CSS:

.image-holder {
  position: relative;
}
.image-holder:before {
  background: rgba(255, 255, 255, 0.5);
  position: absolute;
  content: '';
  width: 20%;
  bottom: 0;
  left: 0;
  top: 0;
}

.image-holder {
  position: relative;
  overflow: hidden;
}
.image-holder:before {
  background: rgba(255, 255, 255, 0.5);
  position: absolute;
  content: '';
  width: 20%;
  bottom: 0;
  left: 0;
  top: 0;
}
.image-holder img {
  display: block;
  height: auto;
  width: 100%;
}
<div class="image-holder">
  <img src="https://i.imgur.com/waDgcnc.jpg" />
</div>

关于html - 如何在图像上方创建一个图层(不透明)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43732439/

上一篇:jquery - 如何使 div 覆盖背景图像?

下一篇:css - html表格的圆 Angular

相关文章:

html - Vue.js - 如何使用 Enter 键提交表单?

html - 如何使文本在 CSS 中创建的框下对齐

c# - 添加母版页后图像不会呈现在我的 aspx 页面上..如果没有更改 ID ..还有什么原因?

html - 为什么#shadow-root 在我的文档中,为什么它会覆盖我的 CSS

html - 将 div 的右侧设为箭头

css - 如何使用 CSS 创建向下箭头?

HTML 和 CSS - 导航栏不会使用 float left 水平 float

javascript - 更改另一个元素的 CSS

css - IE7 : Why do unrelated cells change width when colspan'd cells contents grow wide?

html - 如何将特定形状应用于 div?