html - CSS/HTML 标题背景颜色未覆盖整个页面宽度

标签 html css background header background-color

Image with visual aid for what I am trying to do

你好,

我正在设计一个网页,我正在尝试让我的背景颜色覆盖整个页眉区域。但是,它始终有一个区域作为主页的背景。我试过添加边框并弄乱填充,但所做的只是减少标题内的信息。

有没有办法让页眉的背景颜色到达页面顶部并一直延伸到页面两边?

/* our body class */

body {
  background-color: #0077BE;
}
header {
  width: 100%;
  background-color: #1C39BB;
  color: white;
}
<body>
  <header>
    <h1>Welcome to Samuel Ohrenberg's portfolio!</h1>
    <center>
      <ul class='navList'>
        <li class='navButton' a href='index.html'>Home</text>
          <li>
            <div class="dropdown">
              <button class="dropbtn">&#8659; Portfolio Items &#8659;</button>
              <div class="dropdown-content">
                <a href="programPage.html">Programs</a>
                <a href="otherProjects.html">Other Projects</a>
              </div>
            </div>
            <li class='navButton' a href='videoInterview.html'>Video Interviews</text>
      </ul>
    </center>
  </header>
</body>

最佳答案

您正在挑战 body 的默认边距。只需从正文中删除默认边距:

body
{
    background-color: #0077BE;
    margin:0;
}

header
{
    width: 100%;
    background-color: #1C39BB;
    color: white;
}
<body>
    <header>
        <h1>Welcome to Samuel Ohrenberg's portfolio!</h1>
        <center>
            <ul class='navList'>
                <li class='navButton' a href='index.html'>Home</text>
                <li> 
                    <div class="dropdown">
                    <button class="dropbtn">&#8659; Portfolio Items &#8659;</button>
                        <div class="dropdown-content">
                            <a href="programPage.html">Programs</a>
                            <a href="otherProjects.html">Other Projects</a>
                        </div>
                    </div>
                <li class='navButton' a href='videoInterview.html'>Video Interviews</text>
            </ul>
        </center>
    </header>
</body>

关于html - CSS/HTML 标题背景颜色未覆盖整个页面宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39429770/

相关文章:

javascript - 为什么在 onsubmit 返回 undefined 之后提交表单?

css - 不要为可拖动元素显示重影

javascript - Framework7 和 Material Design : Styling not rendered

Java Swing JFrame 背景未显示

javascript - ECHO 双单引号

html - 列计算

css - 如何覆盖样式 angular-bootstrap-datepicker - "ng-datepicker"

html - 跨度超出 div 且不完全适合

android - android ListView 中的行图像更改?

ios - 如何 Hook ios 连接更改