html - 为图像添加黑色透明度
问题描述
这是我的 html 和 CSS 代码:
<!DOCTYPE html>
<html>
<head>
<title>Background Image</title>
<meta charset="utf-8"></meta>
<meta name="viewport" content="width=device-width, initial-scale=1" ></meta>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" />
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
</head>
<style type="text/css">
body{
margin-top: 53px;
}
.jumbotron {
background-image: url("background1.jpg");
text-align: center;
height:522px;
background-size: cover;
}
</style>
<body>
<section id="page-top">
<div class="jumbotron">
<p data-aos="zoom-out" data-aos-delay="500" style="font: 120px Verdana,sans-serif; margin-top: 35px; color: black; animation-duration: 2s; animation-iteration-count:infinite; animation-delay: 1s;" class="lead pulse mb-5 green pb-5 aos-init aos-animate">Matt Williams</p>
<p data-aos="zoom-out" data-aos-delay="500" style="font: 20px Georgia,serif;font-style:italic; line-height: 1.6; color:white;animation-duration:2s;animation-iteration-count:infinite; animation-delay:1s;" class="lead pulse mb-5 lightGreen pb-5 aos-init aos-animate d-none d-lg-block">Lorem Ipsum.<br>Lorem Ipsum.</p>
</div>
</section>
</body>
</html>
解决方案
您可以在 url 背景前添加透明渐变:
.jumbotron {
background-image: linear-gradient(0deg, rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0.5)), url("background1.jpg");
}
例如:
body {
background-image: linear-gradient(0deg, rgba(0,0,0,0.5), rgba(0,0,0,0.5)), url(https://picsum.photos/id/896/640/480);
}
推荐阅读
- javascript - 虽然循环崩溃,但递归函数抛出最大调用堆栈超出错误
- angular - Angular Reactive Forms - 实现输入组件包装器的最佳方式?
- c - DFS 函数中的分段错误
- java - Android studio,在定时器计划(JAVA)之间启动任务
- assembly - 堆栈指针如何从虚拟内存转换为物理内存
- image-processing - 错误:不一致的参数(op1 是 1x3,op2 是 1x2)
- android - Android Studio:尝试理解编译和实现的区别
- microsoft-graph-api - 更新 privilegedRoles 需要哪些额外权限?
- flutter - Flutter,FutureBuilder 快照错误:“int”类型不是“String”类型的子类型
- python-3.x - 如何正确将此字符串转换为整数?