首页 > 解决方案 > 我试图弄清楚如何让 div *topnav* 背景颜色适合页面宽度

问题描述

我试图弄清楚如何让 divtopnav背景颜色从一边到另一边适应页面宽度而没有间隙。我希望你明白我的意思。如果您需要更多信息,请告诉我。显示差距的页面: 显示间隙的页面

HTML 和 CSS 代码

body {background-color: burlywood;}
  #heading1{position: relative; text-align: center; top: 50px;}
  #topnav{background-color: chocolate;
  font-size: 30px; 
  text-align: center;
  overflow: hidden;
  position: relative;
  word-spacing: 70px;
  width: 100%; height: 100%;
  bottom: 80px;
}
 <!DOCTYPE html>
<html>
  <head>
      <link rel="stylesheet" href="main.css">
      <title></title>
  </head>
  <body>
    <h1 id="heading1">Hello World</h1>
    <div id="topnav">
      <nav>
        <a href="#"> About</a>
        <a href="#"> sales</a>
        <a href="#"> cart</a>
        <a href="#"> home</a>
      </ul>
      </nav>
    </div>
  </body>
</html>

标签: htmlcss

解决方案


穿上 body { padding:0; margin:0; }风格


推荐阅读