0

看,我知道有很多线程有很多解决方案,但没有一个对我有用。我是一个初学者,我刚开始用 HTML 制作网站。我之前尝试过做一个网站,但我遇到了同样的问题。我已经删除了以前的一个并制作了一个新的,但我仍然无法解决这个问题。

我尝试过但并没有真正起作用的方法:

  • 将高度设置为 100% / 100vh(方法一)
  • 将 div min-height 设置为 100%,给它绝对位置并执行以下操作:

    top: 0px
    
    bottom: 0px
    

(方法二)

当我执行方法 1 时,当您可以滚动页面时,我的 div 不会拉伸到页面底部,而是拉伸到浏览器窗口的 100% 高度。

当我执行方法 2 时,div 就会消失。我没有强迫边界伸展,所以你仍然可以看到它,但如果我这样做,它就会消失。

顺便说一句,我只是一个初学者,我什至还不知道 JavaScript、jQuery 等的基础知识,所以我想只使用纯 HTML 和 CSS 而不是 JavaScript 和其他东西,直到我学习它们。

编辑:添加文本时,DIV 也需要拉伸,实际上这是我的主要问题之一。

4

1 回答 1

1

试试这个……您可以随意调整样式以使其成为您想要的方式。我把你的边框放在里面.Mainhtml, body改为height: 100%

注意:由于您对 Main 的边距使用了绝对定位,因此定位看起来很时髦。我会改变的。但是,如果您将代码复制到您的页面,它可能就是您的目标。

html, body {
    height: 100%;
}

.page {
    background: linear-gradient(#2d5aa4, #03637c);
    height: 100%;
    margin: 0;
    background-repeat: no-repeat;
    background-attachment: fixed;
    position: relative;
}

.NavigationBar {
    background: linear-gradient(to right, #636363, #4e4e4e);
    position: absolute;
    left: 0px;
    top: 0px;
    bottom: 0px;
    width: 220px;
    min-height: 100%;
    z-index: 2;
    font-family: BloggerSans;
    font-size: 1.5em;
}
.NavigationBarBorder {
    background: linear-gradient(to right, #292929, #171617);
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    width: 10px;
    min-height: 100%;
    z-index: 3;
}

.MainParent {
    position: relative;
    min-height: 100%;
}

.NavigationTop {
    background: linear-gradient(#636363, #4e4e4e);
    position: absolute;
    left: 220px;
    width: calc(100vw - 220px);
    height: 75px;
    z-index: 1;
    font-family: Jaapokki;
    font-size: 2em;
}

.Main {
    background: linear-gradient(#ffffff, #e8e8e8);
    position: absolute;
    top: 20vh;
    bottom: 0px;
    width: calc(100vw - 440px); /* set your width */
    left: 220px;
    margin-left: 90px; /*set your margin here */
    min-height: 100%;
    z-index: 4;
    padding-left: 40px;
}

.MainBorder {
    background: linear-gradient(#f79104, #e9720d);
    position: absolute;
    top: -10px; 
    left: 0;
    width: 40px;
    min-height: 100%;
}

h1 {
    font-family: 'Jaapokki';
    text-align: center;
    font-size: 3em;
}

.Text {
    font-family: 'BloggerSans';
    font-size: 2em;
}
<body class="page">
    <div class="MainParent">
        <nav class="NavigationBar">
            <div class="NavigationBarBorder"></div>
            Table of content
        </nav>
        <header class="NavigationTop">
            Navigation
        </header>
        <div class="Main">
            <h1>Title</h1>
            <div class="Text">
                Text </br>
            </div>
            <div class="MainBorder"></div>
        </div>
    </div>
</body>

于 2016-10-04T18:02:50.083 回答