html - 导航栏没有完全覆盖

标签 html css

我正在尝试让我的导航栏覆盖所有右侧,如图所示。我想不通。我尝试了一切,但仍然无法弄清楚。任何建议表示赞赏。

<!doctype html>
<html lang="en">
<head>
<title>
Lighthouse Island Bistro
</title>
<link rel="stylesheet" type="text/css" href="tes.css">
<meta charset="utf-8">
</head>
<body>
<div id="wrapper">
<header>
<h1>Lighthouse Island Bistro</h1>
</header>
<nav>
<ul>
<li><a href="index.html">Home</a></li>
<li><a href="menu.html">Menu</a></li>
<li><a href="map.html">Map</a></li>
<li><a href="contact.html">Contact</a></li>
</ul>
</nav>
<main>
<h2>Locally Roasted Free-Trade Coffe</h2>
<p>Indulge in the aroma of freshly ground coffe. Speciality drinks are               
available hot or cold</p>
<h2>Speciality Pastries</h2>
<p>Enjoy a selection of our fresh-baked, organic pastries, including     
fresh-fruit muffins, scones, croissants, and cinnamon rolls.</p>
<h2>Lunchtime is Anytime</h2>
<p>Savor delicios wraps and sandwiches on hearty, whole-grain breads with     
locally-grown salad, fruit, and vegetables.</p>
<h2>Panoramic View</h2>
<p>Take in some scenery! <br> The top of our lighthouse offers a 
panoramic view of the countryside. Challenge your friends to climb our     
100-stair tower.</p>
</main>
<footer>
Copyright &copy; 2016
</footer>
</div>
</body>
</html>

这是我的 CSS:

body
{
background-color: #010d91; 
margin: 0;
}
#wrapper
{
width: 80%;
margin: 0 auto;
background-color: white;
color: black;
}
h1
{
font-size: 50px;
text-align: center;
}
header
{
background-color: #5995f7;
padding: 10px 10px 10px 10px;   
}
nav
{
float: right;
width: 150px;
font-weight: bold;
letter-spacing: 0.1em;
}
main
{
padding:10px 20px;
color: #000000;
display: block;
overflow: auto;
}
h2
{
color: #869dc7;
}
nav ul
{
list-style-type: none;
margin: 0;
padding: 0;
}
nav a
{
text-decoration: none;
padding: 20px;
display: block;
background-color: #89c6ed;
border-bottom: 1px solid #FFFFFF;
}
nav a:link
{
color:#ffffff
}
nav a:visited
{
color: #eaeaea;
}   
nav a:hover
{
color: #869dc7;
background-color: #eaeaea;
}
footer
{
text-align: center;
font-style: italic;
font-size: small;
padding-top: 5px;
padding-bottom: 5px;
background-color: #5995f7;
}

我的看起来像这样: https://i.imgur.com/PKaa0W5.png

我希望我的导航栏覆盖整个内容,就像下面这样: https://i.imgur.com/h2navpU.png

最佳答案

我只是对您的代码进行了一些更改,希望它能对您有所帮助。谢谢

包装你的 <nav><main><div id="content-wrapper">并为 content-wrapper 编写 CSS并添加 background-color: #89c6ed;nav CSS

#content-wrapper {
    display: flex;
    flex-direction: row-reverse;    
}

body {
    background-color: #010d91; 
    margin: 0;
}
#wrapper {
    width: 80%;
    margin: 0 auto;
    background-color: white;
    color: black;
}
h1 {
    font-size: 50px;
    text-align: center;
}
header {
    background-color: #5995f7;
    padding: 10px 10px 10px 10px;   
}
nav {
    background-color: #89c6ed;
    float: right;
    width: 150px;
    font-weight: bold;
    letter-spacing: 0.1em;
}
main {
    padding:10px 20px;
    color: #000000;
    display: block;
    overflow: auto;
}
h2 {
 color: #869dc7;
}
nav ul {
    list-style-type: none;
    margin: 0;
    padding: 0;
}
nav a {
    text-decoration: none;
    padding: 20px;
    display: block;
    background-color: #89c6ed;
    border-bottom: 1px solid #FFFFFF;
}
nav a:link {
    color:#ffffff
}
nav a:visited {
    color: #eaeaea;
}   
nav a:hover {
    color: #869dc7;
    background-color: #eaeaea;
}
footer {
    text-align: center;
    font-style: italic;
    font-size: small;
    padding-top: 5px;
    padding-bottom: 5px;
    background-color: #5995f7;
}

#content-wrapper {
    display: flex;
    flex-direction: row-reverse;    
}
<!doctype html>
<html lang="en">
  <head>
    <title>Lighthouse Island Bistro</title>
    <link rel="stylesheet" type="text/css" href="tes.css">
    <meta charset="utf-8">
  </head>
  <body>
    <div id="wrapper">
      <header>
        <h1>Lighthouse Island Bistro</h1>
      </header>
      <div id="content-wrapper">
        <nav>
          <ul>
            <li><a href="index.html">Home</a></li>
            <li><a href="menu.html">Menu</a></li>
            <li><a href="map.html">Map</a></li>
            <li><a href="contact.html">Contact</a></li>
          </ul>
        </nav>
        <main>
          <h2>Locally Roasted Free-Trade Coffe</h2>
          <p>Indulge in the aroma of freshly ground coffe. Speciality drinks are available hot or cold</p>
          <h2>Speciality Pastries</h2>
          <p>Enjoy a selection of our fresh-baked, organic pastries, including fresh-fruit muffins, scones, croissants, and cinnamon rolls.</p>
          <h2>Lunchtime is Anytime</h2>
          <p>Savor delicios wraps and sandwiches on hearty, whole-grain breads with locally-grown salad, fruit, and vegetables.</p>
          <h2>Panoramic View</h2>
          <p>Take in some scenery! <br> The top of our lighthouse offers a panoramic view of the countryside. Challenge your friends to climb our     
    100-stair tower.</p>
        </main>
      </div>
      <footer>
        Copyright &copy; 2016
      </footer>
    </div>
  </body>
</html>

关于html - 导航栏没有完全覆盖,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55425879/

相关文章:

javascript - 围绕 Canvas 中的某个点旋转矩形

html - 如何让验证器允许空格?

javascript - 删除一个 li 元素不起作用

html - 在wordpress post中添加默认代码

javascript - 如何使用 JavaScript 对元素重新排序?

javascript - 使用 LESS 的 CSS nth-child 调节?

CSS:在 x 和 y 之间缩进元素

html - 长页面高度和背景重复问题

html - 在 Jumbotron 顶部的中心添加一个半圆

html - Material 设计图标,如何将它们作为文本居中?