html - 如何将页面从顶部拉伸(stretch)到底部?

标签 html css stretching

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

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

  • 将高度设置为 100%/100vh(方法一)
  • 将 div 最小高度设置为 100%,为其指定绝对位置并执行此操作:

    top: 0px
    
    bottom: 0px
    

(方法二)

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

当我执行方法 2 时,div 就消失了。我没有强制拉伸(stretch)边框,所以您仍然可以看到它,但如果我这样做,它就会消失。

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

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

最佳答案

试试这个……您可以随意调整样式以使其成为您想要的方式。我将你的边框放在 .Main 中并将 html, 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>

关于html - 如何将页面从顶部拉伸(stretch)到底部?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39858134/

相关文章:

html - 如何在 html/css 中拉伸(stretch)图像片段

javascript - 如何使用不同的颜色使用 CSS 填充 chrome 中输入[类型 ="range"] 的左侧?

javascript - 同位素 : reorder or shuffle elements based on width

html - 如何用 sprite 替换按钮中的 img 并使其对齐?

php - 使用自动对焦打开模态弹出窗口

ios - 如何阻止图像在 UIImageView 中拉伸(stretch)?

html - CSS 菜单栏仅在 IE11 中隐藏在 pdf 下方

html - 为什么第一列在此表中展开?

html - 幻灯片放映位置随不同大小的不同计算机而变化

ios - 替换 UIView 的 contentStretch?