【问题标题】:Semi-transparent colour layer over image?图像上的半透明颜色层?
【发布时间】:2019-01-03 00:18:26
【问题描述】:

有没有办法使用img 标签在图像上添加半透明层?我也在使用引导程序并试图避免使用background-image CSS 解决方案,因为标签提供了一种快速响应填充父 div 的方法。

HTML

<div id="homebackground">
   <div id="bgcont">
     <b-img id="fitfill" :src="require('../assets/homebg1.jpg')" fluid-grow alt="Responsive image"/>
   </div>
</div>

CSS

#bgcont{
    background-color: rgba(0, 0, 0, 0.5);
  }

  #fitfill{
    max-width: 100%;
    max-height: 100%;
  }

  #homebackground{
    height: 91.5%;
    width: 100%;
    margin: 0;
    padding: 0;
  }

【问题讨论】:

    标签: html css vue.js bootstrap-4


    【解决方案1】:

    您可以使用 css ::after 伪元素:

    #bgcont::after {
        content: ""; // ::before and ::after both require content
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background-color: rgba(0, 0, 0, 0.5);
    }
    

    【讨论】:

    • 效果很好!透明层覆盖div 正上方#homebackground 的一些div 元素是否有原因?我尝试使用z-index 没有任何运气。
    • 您尝试了多少 z-index 值?您是否尝试了负值。很难知道发生了什么,因为我看不到你的 CSS。
    • 抱歉不是很清楚。我朝着不同的方向前进,并将图像设置在身体中,而不是摆脱了许多其他问题。谢谢
    猜你喜欢
    • 2012-02-29
    • 2021-03-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-01
    • 2012-10-21
    • 1970-01-01
    相关资源
    最近更新 更多