html - 容器 div 仅达到视口(viewport)的 100%

标签 html css

我四处搜索并找到了很多解决这个问题的方法,但似乎没有一个对我有用。

我试图让 .containerBody div 一直延伸到页面底部。当页面加载时它看起来很好,但在包含您需要滚动查看的内容的页面上,.containerBody div 在视口(viewport)底部结束(或者,页面加载时在视口(viewport)底部)。对于内容适合初始屏幕的页面,这显然不是问题。但是,对于包含更多内容的任何页面,.containerBody 只是中途结束。

CSS

html, body {
    padding: 0;
    margin: 0;
    min-height: 100%;
    font-family: Arvo, serif;
    font-weight: normal;
    font-size: 11.5px;
    color: #333;
}

.containerBody {
    width: 1000px;
    height: 1000%;
    background-color: #FCFCFD;
    margin: 0 auto;
    position: relative;
}

#tagtop {
    width: 240px;
    height: 110px;
    margin-top: 0px;
    margin-left: 120px;
    position: relative;
}

.topContent {
    float: left;
    clear: both;
    width: 340px;
    padding-left: 647px;
    margin-top: -95px;
    position: relative;
    font-size: 10px;
}

.topContent a {
    color: #333;
}

.topContent a:hover {
    color: #E9194E;
}

.bonusText {
    display: inline;
    font-family: Arvo,serif;
    font-size: 13.25px;
    font-weight: bold;
    color: #E9194E;
}

HTML

<body>
<div class="containerBody">
    <div id="tagtop"> <a href="index.html"><img src="image.png"</img>
    <h1>Text<div class="bonusText">text</div></h1></a>
    </div>
    <div class="topContent"> 
        Text
        <a href="www.google.ca">Link1</a>
        <a href="www.google.ca">Link2</a>
    </div>
    <div class="workcontainer">
        Title<br><br>
        <img src="assets/placeholder.png">
        <div class="workwords">Text</div>
        <div class="worktags">Text</div>
        <img src="assets/placeholder.png">
        <img src="assets/placeholder.png">
        <img src="assets/placeholder.png">
    </div>
</div>
</body>

我已经尝试使用最小高度并尝试将顶部和底部位置设置为 0,但我没有成功地使容器拉伸(stretch)到页面底部,而不是加载视口(viewport)的底部。帮忙?

最佳答案

您需要为 body 设置 100% 的宽度和 100% 的高度,并将显示设置为阻塞。

.containerBody {
 width : 1000px;
 height :100%;
 background-color: #ccc;
 margin: 0 auto;
 display: block;
 }
 html, body {
 padding:0;
 margin:0;
 min-height:100%;
 font-family:Arvo, serif;
 font-weight:normal;
 font-size:11.5px;
  color:#333;
height: 100%;
width: 100%;
}

查看我的 jsfiddle

关于html - 容器 div 仅达到视口(viewport)的 100%,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17052082/

相关文章:

html - 如何在移动和桌面设备中显示不同的图像

php - 如何使用分页实现同位素

javascript - 如何在 JavaScript 中实现 html 语法荧光笔?

javascript - 禁用按钮仅在第一次和刷新页面时有效

html - 为站点实现非对称背景图像

javascript - jQuery hide() 动画向右滑动

html - 如何在 IE 的列中显示 ul 列表?

html - Android 原生视频全屏问题

html - 将水平导航更改为垂直

如果段落包含复选框,则 Javascript 将类添加到段落