css - 如何修复滚动时通过标题显示的文本?
问题描述
我正在为学校做一个项目,但我遇到了一个问题。正如你所看到的,我的文本通过我的标题,但我需要它在下面,所以它在滚动时不可见。但我不知道如何让它消失。
如果有人知道如何解决它会很棒,我将不胜感激
我的代码:
header {
position: fixed;
width: 100%;
height: var(--heading-height);
}
.sticky {
position: fixed;
top: 0;
width: 100%
}
/
.sticky + .content {
padding-top: 102px;
}
header::before {
content: "";
display: block;
position: absolute;
left: 0;
bottom: 6em;
width: 100%;
height: calc(var(--heading-height) + 10em);
z-index: -1;
transform: skewY(-3.5deg);
background:
linear-gradient(rgba(0,0,0,.6), rgba(0,0,0,.6)),
url(logo.gif) repeat,
linear-gradient(#4e4376, #2b5876);
background-image: 10px;
background-size: contain;
border-bottom: .2em solid #fff;
}
h1 {
font-size: calc(2.8em + 2.6vw);
font-weight: 700;
letter-spacing: .01em;
padding: 10rem 0 0 4.5rem;
text-shadow: .022em .022em .022em #111;
color: #fff;
}
main {
padding: calc(var(--heading-height) + 1.5vw) 4em 0;
}
p {
font-size: calc(2em + .25vw);
font-weight: 400;
line-height: 2;
margin-bottom: 1.5em;
color: #fcfcfc;
}
#seriesQuiz {
border-radius: 25px;
border: 2px solid;
border-color: white;
background-color: black;
padding: 7%;
}
#seriesGames {
border-radius: 25px;
border: 2px solid;
border-color: white;
background-color: black;
padding: 7%;
position: center;
}
#seriesGamesTekst, #seriesQuizTekst {
font-size: 20px;
border-radius: 1px;
border: 2px solid;
border-color: white;
background-color: black;
padding: 6%;
position: relative;
top: -180px;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>LM Quizzie</title>
<link rel= "stylesheet" href="indexstyle.css">
<script src="indexscript.js" defer></script>
</head>
<body>
<header class="header">
<h1>LM Quizzie</h1>
</header>
<style>
div {
border: 1px solid black;
padding-top: 5px;
padding-bottom: 100px;
width: 300px;
margin-top: 600px;
margin-left: 200px;
}
#seriesQuiz {
background-image: url('netflix4.png');
background-size: cover;
background-position: center;
}
#seriesGames {
background-image: url('games.png');
background-size: cover;
background-position: center;
}
</style>
</head>
<body>
<h2>-</h2>
<div id="seriesQuiz"><p id="seriesQuizTekst">Neem de quiz die gaat over series.</p>
<script type="text/javascript">
function naarQuiz1() {
document.getElementsByClassName("button").onclick = function () {
link.href = "https://86613.ict-lab.nl/quizz/Quizz/quiz2.html";
};
}
</script>
<a href="https://86613.ict-lab.nl/quizz/Quizz/quiz.html" class="button" id="link">
<br> Neem de quiz</a>
<script type="text/javascript">
function naarQuiz1() {
document.getElementsByClassName("button1").onclick = function () { Neem de quizz
link.href = "https://86613.ict-lab.nl/quizz/Quizz/quiz2.html";
};
}
</script>
</div>
<div id="seriesGames"><p id="seriesGamesTekst">Neem de quiz die gaat over games.</p>
<script type="text/javascript">
function naarQuiz1() {
document.getElementsByClassName("button").onclick = function () {
link.href = "https://86613.ict-lab.nl/quizz/Quizz/quiz2.html";
};
}
</script>
<a href="https://86613.ict-lab.nl/quizz/Quizz/quiz2.html" class="button1" id="link">
<br> Neem de quiz</a>
<script type="text/javascript">
function naarQuiz1() {
document.getElementsByClassName("button1").onclick = function () {
link.href = "https://86613.ict-lab.nl/quizz/Quizz/quiz2.html";
};
</body>
</html>
解决方案
所以你有一个定位问题,可以用 CSSz-index
属性解决。
您可以将 设置header
为具有 high z-index
,这将使其显示在所有内容之上,除非您将元素设置为具有更高的z-index
。
.header {
z-index: 999;
}
在你的情况下,我认为标题上的 z-index 是最好的(我已经针对类 .header ,就好像你有更多的元素,你不希望它们最有可能处于高 z-index )
您可以在MDN上查看有关z-index
值的更多信息
推荐阅读
- python - Python中的格式化list.sort函数
- xaml - 如何在 NavigationView 中隐藏垂直滚动条?
- redis - 如何将 Redis 日志转储到文件目标?
- php - 在 url 中设置斜杠时资产无法正确加载
- mysql - MySQL 在 LIKE 的查询中重写字符串?
- python - 在没有任意字符串的python中加载和使用配置文件
- c# - 无法注册 Mongo 映射
- python - MacOS:在python shell中插入一列用鼠标选择的值,由CMD + C复制并将其作为列直接插入到另一个编辑的vim文件中
- java - 我在我的 Postman 中遇到了这个错误(POST 和 DELETE 出现了这个错误),希望有人能解决这个问题
- postgresql - 从出现在多个表中的列中动态选择出现次数最多的值