我正在做一个学校项目,我必须在HTML & CSS中创建导航栏。我有以下代码,但它不像我希望的那样快速响应。HTML&CSS导航栏错误
当我缩小屏幕时,文字变得更接近。我如何在p
类之间添加一个固定的空间或者使用其他方法来解决这个问题?
HTML:
<!DOCTYPE html>
<html>
<head>
<title>Header</title> <!-- This is the page title -->
<link href="style.css" rel="stylesheet" type="text/css"> <!-- This adds the stylesheet so that "style.css" can edit this page -->
<meta content="Hugh Chalmers" name="author">
</head>
<body>
<div class="header"> <!-- This will be the Navigation Bar part of the page. Currently, it is invisible, but the CSS will change that. -->
<p class="text" id="home">Home</p>
<p class="text" id="about">About Us</p>
<p class="text" id="contact">Contact Us</p>
<p class="text" id="products">Products</p>
<p class="text" id="forums">Forums</p>
</div>
</body>
</html>
CSS:
.header {
position: absolute;
width: 100%;
height: 10%;
left: 0;
top: 0;
background-color: red;
}
.text {
font-family: font-family: 'PT Sans',sans-serif;
font-size: 30px;
font-weight: 700;
color: #fff;
position: absolute;
}
#home {
position: absolute;
left: 5%;
}
#about {
position: absolute;
left: 15%;
}
#contact {
position: absolute;
left: 27%;
}
#products {
position: absolute;
left: 40%;
}
#forums {
position: absolute;
left: 53%;
}
这当你的页面增长时,绝对定位将会变成真正的熊。我肯定会建议考虑少做一些手动的事情,页面可以根据一些温和的规则自然地流动你的内容。 –
你有真正凌乱的CSS样式 –