gpt4 book ai didi

html - 固定位置标题重叠

转载 作者:行者123 更新时间:2023-11-27 23:41:53 25 4
gpt4 key购买 nike

好吧,我有两个问题。一个是每当我尝试做 position:fixed;在 .header 上,它在标题底部添加了空间,并使 .main-content 位于标题后面,并在标题顶部添加了边距。另一个问题是,每当我没有固定位置时,标题和主要内容之间就会有空间,并且出于某种原因,如果我在主要内容上放置边框,空间就不存在了。我查看并查看了我的代码,试图找出它有什么问题,但我似乎找不到任何东西。 感谢您的帮助!

/***********************************
LOGO
***********************************/
.header{
background-color: skyblue;
margin:0;
padding:0;
width: 100%;
}
.logo{
text-align: left;
display: block;
margin:0 15px 0px 15px;
}
#logo-large{
display: inline;
font-size: 3em;
font-weight: 200%;
font-family: 'Dosis' , sans-serif;
}
#logo-small{
display: inline;
font-weight:0;
font-size: 2.5em;
font-family: 'Dosis' ,sans-serif;
}
/************************************
NAVIGATION
************************************/
nav ul{
list-style-type:none;
/****display: block;
padding: 5px;
margin: 5px;
text-align: center;****/
}
nav{
display:inline;
float: right;
}
nav ul li{
display: inline-block;
padding: 5px 0px;
margin: 0;
}
nav ul li a{
text-decoration: none;
padding:20px 12px 12px 12px;
color:black;
font-family: 'Muli', sans-serif;
font-size: 1.25em;
}
nav ul li a:active, nav ul li a:hover{
background-color: deepskyblue;
color: white;
}
/*************************************
main content
*************************************/
.main-content{
background-color: grey;
font-family: 'Muli', sans-serif;
margin:0;
padding:10px;
border: 1px solid black;
}
body{
margin:0;
padding:0;
}
<!DOCTYPE html>
<html>
<head>
<title>FatHead | Blog</title>
<link href='http://fonts.googleapis.com/css?family=Dosis:400,500,600,700,800|Muli:400,300italic,400italic' rel='stylesheet' type='text/css'>
<link rel="stylesheet" href="css/style.css" type="text/css">
</head>
<body>
<div class="header">
<div class="logo">
<h1 id="logo-large">FAT</h1> <h1 id="logo-small">HEAD</h1>
<nav>
<ul>
<li><a href="index.html">Home</a></li>
<li><a href="#">About</a></li>
<li><a href="#">Contact</a></li>
<li><a href="#">Categories</a></li>
</ul>
</nav>
</div>
</div>
<div class="main-content">
<h1>Welcome to my blog!</h1>
<p>This would be where all the content inside the blog post goes.</p>
</div>
</body>
</html>

最佳答案

现在只需添加到此 css 定义您的 .header position :fixed 并定义您的 body padding-top:65px;

 .header{
position: fixed;
left:0;
right:0;
top:0;
}
html body {
padding-top: 65px;
}

关于html - 固定位置标题重叠,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31377189/

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