html - 为什么导航栏后没有显示我的文字?
问题描述
我对这整个 HTML/CSS 很陌生。在查阅了一些教程后,我设法制作了一个基本的导航栏,但现在的问题是我输入的任何文本都没有出现在导航栏下。我错过了什么吗?
HTML:
body{
margin:0;
}
nav{
position: fixed;
top:0;
width:100%;
background-color:#f2bbac ;
float: right;
height:70px;
font-family: 'Quicksand', sans-serif;
}
nav ul{
list-style: none;
padding:0;
margin:0;
}
nav a{
text-decoration: none;
font-size: 20px;
color: white;
text-transform: uppercase;
}
nav a:hover{
color:gray;
}
nav li{
display: inline-block;
margin-left: 40px;
padding: 20px;
}
<!DOCTYPE html>
<html lang="en-us">
<head>
<link href ="stylesheets/mainstyle.css"rel="StyleSheet" type="text/css">
<title>books</title>
<link href="https://fonts.googleapis.com/css2?family=Quicksand&display=swap" rel="stylesheet">
</head>
<body>
<nav>
<ul>
<li><a href="mainpage.html">Home</a></li>
<li><a href="aboutpage.html">About</a></li>
<li><a href="contact.html">Contact Us</a></li>
</ul>
</nav>
<h1>hello there. testing</h1>
</body>
<script src="script.js" async defer></script>
</html>
解决方案
这是由于position: fixed;
. nav
它使底层内容从顶部开始。你必须给h1
. 我之前刚刚添加了一个body
垫片h1
body {
margin: 0;
}
nav {
position: fixed;
top: 0;
width: 100%;
background-color: #f2bbac;
float: right;
height: 70px;
font-family: 'Quicksand', sans-serif;
}
nav ul {
list-style: none;
padding: 0;
margin: 0;
}
nav a {
text-decoration: none;
font-size: 20px;
color: white;
text-transform: uppercase;
}
nav a:hover {
color: gray;
}
nav li {
display: inline-block;
margin-left: 40px;
padding: 20px;
}
<!DOCTYPE html>
<html lang="en-us">
<head>
<link href ="stylesheets/mainstyle.css"rel="StyleSheet" type="text/css">
<title>books</title>
<link href="https://fonts.googleapis.com/css2?family=Quicksand&display=swap" rel="stylesheet">
</head>
<body>
<nav>
<ul>
<li><a href="mainpage.html">Home</a></li>
<li><a href="aboutpage.html">About</a></li>
<li><a href="contact.html">Contact Us</a></li>
</ul>
</nav>
<div style="height: 50px;width: 100%;"></div>
<h1>hello there. testing</h1>
</body>
<script src="script.js" async defer></script>
</html>
推荐阅读
- reactjs - 如果所有记录都已处理,则仅重新加载页面
- azure - 如何使用 python 在 azure blob 存储中为 upload_blob 设置内容类型?
- typescript - 如何使用 typescript-fetch 使用 openapi-generator 生成真正简约的模型接口?
- jupyter-notebook - 是否有自签名 SSL 证书的替代方案?
- python - 有人知道我在哪里可以找到关于 seaborn clustermap 中 clustergrid 的文档吗?
- angular - Electron / Angular项目Onload将图像显示为飞溅
- angular - 如何在 Ionic 应用程序中使用 Angular 格式化 json 输出到 dom 中?
- loops - 引用宏变量
- python - GoogleNet 神经网络中所有 epoch 的精度相同
- java - 使用 Java 正则表达式匹配 + 字符