css - 背景图像被导航栏覆盖
问题描述
我试图让我的图像下拉,所以它不在我的导航栏下。我希望我的背景图像可以通过滚动文本来修复,但我似乎无法让我的图像高度正确。我尝试更改边距和填充,但似乎没有任何效果。
.wrapper {
height: 100%;
line-height: 1.5;
word-spacing: 4px;
letter-spacing: 1px;
}
.fixed-bg {
background-attachment: fixed;
background-repeat: no-repeat;
background-size: cover;
background-position: center center;
height: 100%;
width: 100%;
color: white;
text-align: center;
display: table;
}
.fixed-bg h1 {
display: table-cell;
vertical-align: middle;
color: #993399;
text-transform: capitalize;
text-align: center;
text-shadow: .1rem .1rem .1rem white;
}
.scroll-bg {
background-color: white;
padding: 5px 70px;
color: #676767;
}
.bg-1 {
background-image:url(/Images/annual\ dinner1.jpg) ;
}
.bg-2 {
background-image:url(/Images/donate\ today.jpg) ;
}
@media only screen and (max-device-width: 1366px) {
.wrapper {
background-attachment: scroll;
}
}
解决方案
body {
margin: 0;
font-family: Arial, Helvetica, sans-serif;
}
.hero-image {
background-image: url("https://images.unsplash.com/photo-1626011338327-2723a5268d7a?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=334&q=80");
background-color: #cccccc;
height: 500px;
background-position: center;
background-repeat: no-repeat;
background-size: cover;
position: relative;
}
.hero-text {
text-align: center;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
color: white;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<div class="hero-image">
<div class="hero-text">
<h1 style="font-size:50px">hello</h1>
<h3>Lorem, ipsum dolor sit amet consectetur adipisicing elit. Eos, harum?</h3>
<button>Submit</button>
</div>
</div>
</body>
</html>
推荐阅读
- haskell - 为什么引入严格性的函数称为 seq?
- javascript - Vue.js (vuex)。重新加载页面时,计算属性返回未定义。(vuex 中对象数据的硬编码数组)
- java - 尝试正确设置研磨窗格
- c# - 如何从Arduino记录在C#中串行com端口随机出现的特定变量数据
- r - 一旦 dplyr 已按另一个变量分组,如何为一个变量组合多个文本条目
- node.js - Heroku 应用程序因 ERR_UNKNOWN_FILE_EXTENSION 而崩溃
- dialogflow-es - 当 followupEventInput 有参数时,Dialogflow Google Assisant 中断
- amazon-web-services - 运行 AWS CLI 命令时出现“configparser.DuplicateOptionError”
- python - VS Code 中的 Flake8:未使用的导入未加下划线
- java - 如何使用 BOBJ REST API 实现分页?