繁体   English   中英

如何让我的页脚从顶部覆盖 100% 的页面高度和宽度?

[英]How to make my footer cover 100% height and width of the page from top?

我有一个带有 header、页脚和内容的 html 页面。 当用户点击我的页脚时,我希望页脚从顶部开始覆盖整个页面。 当我将页脚的高度和宽度设置为 100vh 和 100vw 时。 它是从底部开始的。 我如何使它从顶部覆盖? 网页布局的图像

您需要使用percentage %而不是vh/vw/px 您需要设置top:0; height: 100% (设备屏幕的全高)。

 function toggle() { var className = document.getElementById('footer').className; if (className == 'footer') { document.getElementById('footer').innerText = 'Click to minimize'; document.getElementById('footer').className = 'footer full'; } else { document.getElementById('footer').innerText = 'Click to miximize'; document.getElementById('footer').className = 'footer'; } }
 .footer { background-color: #000; color: #FFF; width: 100%; padding: 20px 0; }.full { height: 100%; width: 100%; position: fixed; top: 0px; left: 0px; }
 <h1>My heading</h1> <p> Hello, this click on the footer to expand it. </p> <br> <p> Hello, this click on the footer to expand it. </p> <br> <p> Hello, this click on the footer to expand it. </p> <br> <p> Hello, this click on the footer to expand it. </p> <br> <p> Hello, this click on the footer to expand it. </p> <br> <p> Hello, this click on the footer to expand it. </p> <br> <p> Hello, this click on the footer to expand it. </p> <br> <p> Hello, this click on the footer to expand it. </p> <br> <p> Hello, this click on the footer to expand it. </p> <br> <p> Hello, this click on the footer to expand it. </p> <br> <div id='footer' class='footer' onClick='toggle()'> Click to maximise </div>

尝试这个:

$('.footer').click(function(){
        $(this).toggleClass('new_footer');
    });



.new_footer{
    background-color: #000;
    position: fixed;
    top: 0;'
    left: 0;
    right: 0;
    bottom: 0;
    height: 100vh;
    width: 100%;
    color: #fff;
}
<header>
  My heaader
</header>

<div>content</div>

<div class="footer">
 My footer
</div>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM