html - 线性渐变背景覆盖其他元素(如 img 或文本)

标签 html css bootstrap-4

我正在使用 CSS 和 Bootstrap 4 编写代码。我已经制作了渐变背景,但是当我开始添加其他元素(例如图像或文本)时,它们看起来基本上是不可见的,因为渐变位于它们之上。有解决办法吗?

.background{
    background-image: linear-gradient(to top, black, white);
    opacity: 0.3; 
    }
<html>

<div class="background"> 
    <div class = "row"> 
      <img src"https://devfest.gdg-taipei.org/images/logos/google.svg"> 
    </div> 
</div> 


</html>

最佳答案

尝试这样的事情:

<div class="background"> 
    <div class="background-curtain"></div>
    <div class = "row"> <!--First Section-->
        <img src="img.png"> 
    </div> 
    <div class = "row"> <!--Second Section-->
        <p>Hello</p> 
    </div> 
</div> 

CSS:

.background{ 
        position: relative;
    }
    .background-curtain{
        position: absolute;
        width: 100%;
        height: 100%;
        background-image: linear-gradient(to top, black, white);opacity: 0.3;
        z-index: -100;
    }

关于html - 线性渐变背景覆盖其他元素(如 img 或文本),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52719987/

相关文章:

php - 使 PHP 函数相互协作

javascript - 将div转换为图片,在javascript中的bootstrap modal中显示

html - 在绝对定位的父级中滚动子 div

html - 如何使用div创建表格

html - 固定引导内容

jquery - 如何将嵌套的 div 向上移动两个 div 级别以匹配父级?

html - 如何保持两个并排的 div 元素高度相同?

javascript - 如何更改对象中特定值的字体颜色?

css - 水平滚动页面上 100% 宽度的图像

html - 图片大小在轮播中放大