html - 背景透明但不是文本
问题描述
我有一个问题...我想让我的背景图片半透明。但是,我希望 div 中的文本完全可见。有小费吗?提前致谢
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Stack</title>
<style type="text/css">
#recipebackground{
/* The image used */
background-image: url("../imgs/ajiacobackground.jpg");
/* Full height */
height: 50%;
/* Center and scale the image nicely */
background-position: center;
background-repeat: no-repeat;
background-size: cover;
/*opacity*/
opacity: 0.5;
}
</style>
</head>
<body>
<section id="recipebackground" class="opacitybox">
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<section>
<div class="container" >
<h1 style="font-size: 350%;" class="text-center"><b>It's Lunch-Time!</b></h1>
</div>
</section>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
</body>
</html>
另请注意,我在我的文件中使用引导程序。谢谢
解决方案
你错过了很多东西。首先结构本身是错误的。使用这么多 br 标签是不正确的。考虑到您是此门户的新手,您应该对背景不透明度进行更多研究。
.container{
position: relative;
/* The image used */
background-image: url("https://www.elephantsdeli.com/wp-content/uploads/fly-images/1673/elephants-delicatessen-sack-lunch-order-form-hero-image.jpg-1920x1080.jpg");
/* Full height */
height:100vh;
/* Center and scale the image nicely */
background-position: center;
background-repeat: no-repeat;
background-size: cover;
}
.background {
height: 100vh;
background: rgba(255 , 255, 255, 0.5)
}
.text-center {
padding:50px 0;
}
<div class="container" >
<div class="background">
<h1 style="font-size: 350%;" class="text-center"><b>It's Lunch-Time!</b></h1>
</div>
</div>
检查片段以了解您可以做什么的小预览/想法。
推荐阅读
- bash - Bash 或 cmd 将 Java 标准附加到文本文件中
- javascript - 如何使用隐藏的输入框进行输入?
- python - 如何将用户输入的常量(pi,e)转换为 python 中的浮点数?
- sql - 如何删除/替换 Oracle 结果集中的“sys.DBMSOUTPUT_LINESARRAY”?
- python - Tensorflow / Keras教程保存/加载模型不起作用
- sql - 如何在 sql 中的 datetime2 类型中有两个日期变量?
- node.js - Express 服务器没有在我的 React 生产版本上运行
- java - OpenCV - 删除错误的轮廓
- oauth-2.0 - 如何使用后端服务器对 google home 用户进行身份验证?
- javascript - 颜色不想自动转换