Html 堆叠整页div

Html 堆叠整页div,html,css,Html,Css,在这里拉小提琴: 我试图让每个div填充视口,而不指定像素大小。我该怎么做?目前,div仅与其中的h1和p元素中的文本一样大。我尝试将高度设置为100%,并对html和body元素执行相同的操作 <title>mountains</title> <body> <div id="denali" class="fullPageDiv"> <h1>denali</h1> <p>

在这里拉小提琴:

我试图让每个div填充视口,而不指定像素大小。我该怎么做?目前,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>
使用:

而不是
最小高度

使用:

而不是
最小高度


如果我正确理解你的问题,你必须使用Javascript, 包含jQuery&此代码:

////Checks the viewport height and sets element's height accordingly.
$(".fullPageDiv").css({height:$(window).height()});                        

////If viewport ever re-sized or device (tablet for example) switched from portrait to landscape or vice versa.
                                      $(window).resize(function(){
 $(".fullPageDiv").css({height:$(window).height()});
});

这里是

如果我正确理解您的问题,您必须使用Javascript, 包含jQuery&此代码:

////Checks the viewport height and sets element's height accordingly.
$(".fullPageDiv").css({height:$(window).height()});                        

////If viewport ever re-sized or device (tablet for example) switched from portrait to landscape or vice versa.
                                      $(window).resize(function(){
 $(".fullPageDiv").css({height:$(window).height()});
});

这是

太棒了,这就是我要找的!我发誓我试过了。。。一定有其他css破坏了它。除非将“html,body”组合到一个选择器中会有什么不同……太棒了,这就是我想要的!我发誓我试过了。。。一定有其他css破坏了它。除非将“html,body”组合到一个选择器中会有什么不同……谢谢索尼,这太棒了。如果简单的答案不合适,我将使用jQuery…谢谢索尼,这太好了。如果简单的答案不合适,我将使用jQuery…只是另一个演示而已,只是另一个演示而已
////Checks the viewport height and sets element's height accordingly.
$(".fullPageDiv").css({height:$(window).height()});                        

////If viewport ever re-sized or device (tablet for example) switched from portrait to landscape or vice versa.
                                      $(window).resize(function(){
 $(".fullPageDiv").css({height:$(window).height()});
});