html - 堆叠的整页 div

标签 html css

在这里摆弄:

http://jsfiddle.net/JzbDj/

我试图让每个 div 填充视口(viewport),而不指定像素大小。我怎样才能做到这一点?目前,div 的大小仅与其内部 h1 和 p 元素中的文本一样大。我尝试将高度设置为 100%,并对 html 和 body 元素执行相同的操作...

<title>mountains</title>
<body>
    <div id="denali" class="fullPageDiv">
        <h1>denali</h1>
        <p>Denali is the highest mountain in North America. Due to a disagreement between the Boards of Geographic Names in Alaska and the United States, the peak's official name is Denali according to Alaska and Mount McKinley according to the United States.</p>
    </div>
    <div id="mountlogan" class="fullPageDiv">
        <h1>mount logan</h1>
        <p>Mount Logan is the second tallest peak in North America.</p>
    </div>
</body>
</html>

CSS:

body {
    font: 18px/30px Sans-serif; 
    margin: 0;
    padding: 0;
    min-height:1000px;
}

html {
    margin: 0;
    padding: 0;
    min-height: 100%;
}

.fullPageDiv {
    position: relative;
    min-height: 100%;
    width: 100%;
    overflow: hidden;
}

#denali {
    background-color: red;
}

#mountlogan {
    background-color: green;
}

#citl {
background-color: yellow;
}

#mountsaintelias {
    background-color: blue;
}



#popo {
background-color: red; 
}

最佳答案

用途:

html, body {
    height: 100%;
}

而不是最小高度

<强> DEMO

关于html - 堆叠的整页 div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17224689/

相关文章:

html - 只想将鼠标悬停在一个元素上以更改文本颜色

html - CSS 格式不缩进 ng-repeat 输出的第二行

javascript - 如何实现带有不允许文本在其下方流动的 float 图标的列表项?

html - 如何为该 View 在右侧制作 3 列?

css - 显示合成图层边框(蓝色边框)

javascript - 选择框中的 Google API 字体

php - 在html站点中选择一个月并只读取从mysql中选择的月份

ruby-on-rails - rails : Bootstrap Editing Forms CSS

html - 键盘打开 bootstrap 3 时出现粘性页脚问题

html - 媒体查询在 iframe 中不起作用