css - 图像未显示/z-index 未按预期工作
问题描述
我正在尝试在背景图像的底部放置一个带有天空的分隔线(class="divider-clouds")。出于某种原因,它们只是不会显示 - 似乎云隐藏在背景图像后面。
我一直在玩 z-index 以便将云放在背景图像之上。但似乎也没有帮助。我错过了什么??
HTML:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>TurboTobias</title>
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<section id="hero-section">
<div class="row">
<div class="column hjemmeside-til-skyerne">
<h1>Vil du have
<div class="h1-enhanced">raketfart</div>
<div class="h1-smaller">på din hjemmeside?</div>
</h1>
<span class="sub-h1">Jeg ta'r din hjemmeside til skyerne!</span>
</div>
<div class="column">
<h2>Column 2</h2>
<p>Some text..</p>
</div>
<div class="divider-clouds"></div>
</div>
</section>
</body>
</html>
CSS:
body {
background: #fff;
color: #333333;
height: 100vh;
margin: 0;
box-sizing: border-box;
font-family: open sans,Arial,sans-serif;
}
#hero-section {
background-image: url(https://turbotobias.dk/wp-content/uploads/2019/07/Light-Above-clouds-HD-TurboTobias.jpg);
background-size: cover;
background-attachment: fixed;
background-repeat: no-repeat;
z-index: 1;
position: relative;
}
.row {
height: 100vh;
width: 80%;
max-width: 1080px;
margin: auto;
display: flex;
z-index: 1;
}
.hjemmeside-til-skyerne {
display: flex;
align-self: center;
align-items: center;
flex-direction: column;
}
.hjemmeside-til-skyerne h1 {
font-weight: 700;
font-size: 60px;
color: #303030!important;
line-height: 1em;
text-transform: uppercase;
}
.h1-enhanced {
font-weight: 900;
font-size: 120%;
}
.h1-smaller {
font-size: 70%;
}
.sub-h1 {
font-size: 24px;
color: #303030;
font-weight: 400;
}
.divider-clouds {
background-image: url(https://turbotobias.dk/wp-content/uploads/2019/07/clouds-divider.svg);
background-size: cover;
background-position: center top;
bottom: 0;
height: 100px;
position: absolute;
z-index: 10;
}
我希望云显示在底部,高度为 100px。
解决方案
您应该在 .divider-clouds 元素样式上添加 100% 的 with。
推荐阅读
- python - 看似“垃圾”的请求结果
- c# - 将测试项目 appSettings 附加到 ASP.NET Core 集成测试
- amazon-web-services - AWS lambda 执行仅在我第一次使用“客户函数错误”运行时失败
- angular - 将 js web 模板转换为 Angular 2+ 应用程序
- slack - 带有本地 Web 服务的 Slack 斜杠命令
- c - void * 赋值给 void **
- html - 如何使功能成为指令,我必须在其他组件中使用它
- android - 想要隐藏通知但获取 Context.startForegroundService() 并没有调用 Service.startForeground()
- css - 如何设置 webview 高度以自动响应本机?
- javascript - 查找非指定字符的索引