You need to use percentage %
instead of vh/vw/px
. You need to set top:0;
and height: 100%
(Full Height of device screen).
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>
Try this:
$('.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>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.