我在页面的左侧有一个导航栏,我想让它伸展到页面高度的100%。不仅是视口的高度,还包括滚动之前隐藏的区域。我不想用javascript来完成这个。

它能在HTML/CSS中完成吗?


当前回答

使用表格很简单:

<html>

<head>
    <title>100% Height test</title>
</head>

<body>
    <table style="float: left; height: 100%; width: 200px; border: 1px solid red">
        <tbody>
            <tr>
                <td>Nav area</td>
            </tr>
        </tbody>
    </table>
    <div style="border: 1px solid green;">Content blabla... text
        <br /> text
        <br /> text
        <br /> text
        <br />
    </div>
</body>

</html>

当DIV被引入时,人们非常害怕表格,可怜的DIV变成了隐喻的锤子。

其他回答

简单,只是把它包装在一个表div…

HTML:

<div class="fake-table">
   <div class="left-side">
     some text
   </div>
   <div class="right-side">
     My Navigation or something
   </div>
</div>

CSS:

<style>

 .fake-table{display:table;width:100%;height:100%;}
 .left-size{width:30%;height:100%;}
 .left-size{width:70%;height:100%;}

</style>

我成功地

min-height: 100vh

对于两者,菜单和内容div。

我想在提示一个模态弹出窗口之前覆盖整个网页。我尝试了许多方法使用CSS和Javascript,但没有一个帮助,直到我想出以下解决方案。它对我有用,我希望它也能帮助到你。

<!DOCTYPE html> <html> <head> <style> html, body { margin: 0px 0px; height 100%; } div.full-page { position: fixed; top: 0; bottom: 0; width: 100%; height: 100%; background-color: #000; opacity:0.8; overflow-y: hidden; overflow-x: hidden; } div.full-page div.avoid-content-highlight { position: relative; width: 100%; height: 100%; } div.modal-popup { position: fixed; top: 20%; bottom: 20%; left: 30%; right: 30%; background-color: #FFF; border: 1px solid #000; } </style> <script> // Polling for the sake of my intern tests var interval = setInterval(function() { if(document.readyState === 'complete') { clearInterval(interval); isReady(); } }, 1000); function isReady() { document.getElementById('btn1').disabled = false; document.getElementById('btn2').disabled = false; // disable scrolling document.getElementsByTagName('body')[0].style.overflow = 'hidden'; } function promptModalPopup() { document.getElementById("div1").style.visibility = 'visible'; document.getElementById("div2").style.visibility = 'visible'; // disable scrolling document.getElementsByTagName('body')[0].style.overflow = 'hidden'; } function closeModalPopup() { document.getElementById("div2").style.visibility = 'hidden'; document.getElementById("div1").style.visibility = 'hidden'; // enable scrolling document.getElementsByTagName('body')[0].style.overflow = 'scroll'; } </script> </head> <body id="body"> <div id="div1" class="full-page"> <div class="avoid-content-highlight"> </div> </div> <button id="btn1" onclick="promptModalPopup()" disabled>Prompt Modal Popup</button> <div id="demo"> <h2>Original content</h2> <h2>Original content</h2> <h2>Original content</h2> <h2>Original content</h2> <h2>Original content</h2> <h2>Original content</h2> <h2>Original content</h2> <h2>Original content</h2> <h2>Original content</h2> <h2>Original content</h2> <h2>Original content</h2> <h2>Original content</h2> <h2>Original content</h2> <h2>Original content</h2> <h2>Original content</h2> <h2>Original content</h2> <h2>Original content</h2> <h2>Original content</h2> <h2>Original content</h2> <h2>Original content</h2> <h2>Original content</h2> <h2>Original content</h2> <h2>Original content</h2> </div> <div id="div2" class="modal-popup"> I am on top of all other containers <button id="btn2" onclick="closeModalPopup()" disabled>Close</button> <div> </body> </html>

祝你好运;-)

我也遇到过类似的问题,解决方法是这样的:

#cloud-container{
    position:absolute;
    top:0;
    bottom:0;
}

我想要一个以页面为中心的div高度100%的页面高度,所以我的总解决方案是:

#cloud-container{
    position:absolute;
    top:0;
    bottom:0;
    left:0;
    right:0; 
    width: XXXpx; /*otherwise div defaults to page width*/
    margin: 0 auto; /*horizontally centers div*/
}

你可能需要让一个父元素(或简单的“body”)具有位置:relative;

* {
margin: 0;
}
html, body {
height: 90%;
}
.content {
min-height: 100%;
height: auto !important;
height: 100%;
margin: 0 auto ;
}