html - 线性渐变背景覆盖其他元素(例如 img 或 text)
问题描述
我正在使用 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;
}
推荐阅读
- java - 更新到 androidx 后:“错误膨胀类 android.support.design.widget.NavigationView。” 为什么应用程序崩溃?
- git - 过去承诺中可见的子模块文件夹
- c++ - 由于类型转换问题,C++ / WinRT Coroutine 无法编译
- java - 如何在 Eclipse 中导入 JSON Simple?
- python - 如何将文件夹中的所有文件列出到Excel工作表中
- python - 为什么 .deiconify 函数不起作用?
- ssl - 本地 IIS 中的 SSL 证书
- html - 解析 EntityName 时出错。第 119 行,位置 40
- java - 在 JTextPane 中保存字体
- bash - pyenv:无法激活 virtualenv - 登录时未从 .profile 读取设置