html - 主体边框未到达主体底部

标签 html css border spacing

我试图在我的网页的整个主体周围创建一个边框,但是每当我在 body 标签周围放置一个边框时,它都没有到达底部。此外,由于某种原因,正文和页面底部之间有一个空间。请指教!

这是代码:(参见 https://jsfiddle.net/04tpunop/)

HTML:

<!DOCTYPE html>
<body>
    <header>
        <nav>
            <div id="navBar">
          <a class="hdrBtn">Button</a>
                    <a class="hdrBtn">Button</a>
            </div>
        </nav>
    </header>
    <div id="banner">
            <h1>Content</h1>
            <h1>Content</h1>
            <h1>Content</h1>
    </div>
    <div id="content">
            <h1>Content</h1>
            <h1>Content</h1>
            <h1>Content</h1>
            <h1>Content</h1>
            <h1>Content</h1>
            <h1>Content</h1>
            <h1>Content</h1>
    </div>
</body>

CSS:

@import 'https://fonts.googleapis.com/css?family=Open+Sans';

html {
    background-color: black;
    background-size: 500px;
}

body {
    width: 80%;
    max-width: 1250px;
    margin: 0 auto;
    /*padding: 0 20px;*/
    background-color: white;
    overflow: auto;
  border: 20px solid white;
}

header {
    top: 0;
    width: 80%;
    border-top: 10px solid white;
    border-bottom: 2px solid #ff0000;
    position: fixed;
    z-index: 10;
    background-color: white;
}

#banner {
    width: 80%;
    height: 500px;
    position: fixed;
    top: 68px;
    background-color: blue;
}

#content {
    width: 100%;
    position: relative;
    top: 568px;
    background-color: grey;
    /*height: 1000px;*/
}

a.hdrBtn {
    font-family: 'Open Sans', sans-serif;
    color: black;
    padding: 16px 15px 10px;
    font-size: 30px;
    border: none;
    cursor: pointer;
    position: relative;
    background-color: transparent;
    text-decoration: none;
    outline: none;
    display: inline-block;
    text-align: center;
    -o-transition: color 0.2s linear;
    -moz-transition: color 0.2s linear;
    -webkit-transition: color 0.2s linear;
    -ms-transition: color 0.2s linear;
    transition: color 0.2s linear;
    -o-transition: background-color 0.1s linear;
    -moz-transition: background-color 0.1s linear;
    -webkit-transition: background-color 0.1s linear;
    -ms-transition: background-color 0.1s linear;
    transition: background-color 0.1s linear;
  margin-left: 6%;
}

button.hdrBtn:hover, a.hdrBtn:hover {
    background-color: #f1f1f1;
    color: #ff0000;
}

.center {
    text-align: center;
}

最佳答案

我认为您的 body 可能只是在包裹内容物。尝试在 CSS 中将高度设置为 100%。

如果这不起作用,请尝试将内容包装在高度和宽度设置为 100% 的 DIV 中

关于html - 主体边框未到达主体底部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38886141/

相关文章:

javascript - 如何将警报值添加到元素

javascript - 如何在 Javascript 源数据中使用(添加)行创建回调

javascript - 如何使用 jQuery 使用不同的 CSS?

css - 修复光标输入

c# - 为什么 Razor 在 html 元素上设置的条件样式总是 html 编码不正确

css - IE/Firefox CSS 困惑 : Why does my table have inside borders on Firefox, 而不是 IE?

java - 如何设置嵌套表格无边框?

javascript - 暂停并继续使用 setInterval

javascript - 包含 JS 文件时声明 MIME 类型很重要吗?

C# WPF BorderBrush 不会设置颜色