gpt4 book ai didi

html - 内容超过我的页眉,但不是页脚?

转载 作者:行者123 更新时间:2023-11-28 02:26:00 24 4
gpt4 key购买 nike

由于某种原因,我在 .box 中的内容会覆盖页眉,但在您调整窗口大小时不会覆盖页脚。我试图固定页脚/页眉,因此它们不会移动,并且在调整窗口大小时让内容覆盖它们。但正如我所说,它只适用于页脚,而页眉允许内容覆盖它。所以我想知道我能做些什么来解决这个问题?谢谢。

body {
background-color: #323232;
font-family: Lato;
padding: 0;
margin: 0;
}

nav a {
color: #fff;
text-decoration: none;
padding: 7px 25px;
display: inline-block;
}

.container {
width: 100%;
margin: 0 auto;
}

.fixed-header, .fixed-footer {
width: 100%;
position: fixed;
background: #333;
padding: 10px 0;
color: #fff;
text-align: center;
}

.fixed-header{
top: 0;
}

.fixed-footer{
bottom: 0;
}

.box {
background: #FFFFFF;
padding: 10px;
width: 400px;
height: 600px;
text-align: center;
top: 50%;
left: 50%;
position: absolute;
transform: translate(-50%, -50%);
}
<!DOCTYPE html>

<html lang="en">

<head>
<title>Kumo99.cf</title>
<meta charset="UTF-8">
<link rel="stylesheet" type="text/css" href="css/style.css">
<link rel="icon" href="favicon.ico">
</head>

<body>

<div class="fixed-header">
<div class="container">
<nav>
<a href="index.html">HOME</a>
<a href="projects.html">PROJECTS</a>
<a href="about.html">ABOUT</a>
</nav>
</div>
</div>

<div class="box">
<div class="container">
<img src="images/avatar.png" alt="" class="box-avatar">
<h1>KUMO</h1>
<h5>RANDOM DEVELOPER</h5>
<ul>
<li>I'm Kumo and this is my website. Here I post random releases of development, projects and concepts. Checkout my other pages for more information.</li>
</ul>
</div>
</div>

<div class="fixed-footer">
<div class="container"><a href="https://steamcommunity.com/id/kumo99">Made by Kumo © 2017</a></div>
</div>

</body>
</html>

最佳答案

为 header 设置一个 z-index,其编号高于 .box,默认情况下均为 0。所以,就像尝试 z-index: 999; 你也可以决定为页脚设置一个更高的 z-index 值,尽管它是在 html 布局中的 .box 元素之后添加的,它默认情况下会显示在顶部。

.fixed-header, .fixed-footer {
width: 100%;
position: fixed;
z-index: 999;
background: #333;
padding: 10px 0;
color: #fff;
text-align: center;
}

此外,在示例中,我决定更改 .box CSS。不确定为什么你有其他的 css 样式。我猜你正在做一些不同的事情。

.box {
background: #FFFFFF;
padding: 10px;
width: 400px;
height: 600px;
margin: 0 auto;
padding: 24px 0;
box-sizing: border-box;
text-align: center;
}

body {
background-color: #323232;
font-family: Lato;
padding: 0;
margin: 0;
}

nav a {
color: #fff;
text-decoration: none;
padding: 7px 25px;
display: inline-block;
}

.container {
width: 100%;
margin: 0 auto;
}

.fixed-header, .fixed-footer {
width: 100%;
position: fixed;
z-index: 999;
background: #333;
padding: 10px 0;
color: #fff;
text-align: center;
}

.fixed-header{
top: 0;
}

.fixed-footer{
bottom: 0;
}

.box {
background: #FFFFFF;
padding: 10px;
width: 400px;
height: 600px;
margin: 0 auto;
padding: 24px 0;
box-sizing: border-box;
text-align: center;
}
<!DOCTYPE html>

<html lang="en">

<head>
<title>Kumo99.cf</title>
<meta charset="UTF-8">
<link rel="stylesheet" type="text/css" href="css/style.css">
<link rel="icon" href="favicon.ico">
</head>

<body>

<div class="fixed-header">
<div class="container">
<nav>
<a href="index.html">HOME</a>
<a href="projects.html">PROJECTS</a>
<a href="about.html">ABOUT</a>
</nav>
</div>
</div>

<div class="box">
<div class="container">
<img src="images/avatar.png" alt="" class="box-avatar">
<h1>KUMO</h1>
<h5>RANDOM DEVELOPER</h5>
<ul>
<li>I'm Kumo and this is my website. Here I post random releases of development, projects and concepts. Checkout my other pages for more information.</li>
</ul>
</div>
</div>

<div class="fixed-footer">
<div class="container"><a href="https://steamcommunity.com/id/kumo99">Made by Kumo © 2017</a></div>
</div>

</body>
</html>

关于html - 内容超过我的页眉,但不是页脚?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47958224/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com