简体   繁体   English

页眉和页脚之间高度的计算

[英]Calculation of height between header and footer

I created a sidenav push. 我创建了sidenav推。 I wrote a javascript function to calculate the remaining height between my header and footer as well: 我写了一个javascript函数来计算我的页眉和页脚之间的剩余高度:

function resizeWindow(){
  var headerHeight = $("#header-web").height();
  var footerHeight = $("#web-footer").height();
  var windowHeight = $("html").height();
  var remainHeight = windowHeight-headerHeight-footerHeight;
  $("#mySidenav").css({"height":remainHeight});
}

I then call it inside the one which is responsible of opening the sidenav: 然后我在负责打开sidenav的那个内部调用它:

function openNav() {
  resizeWindow();
  document.getElementById("mySidenav").style.width = "400px";
  document.getElementById("map").style.marginRight = "250px";
}

I'm working on a mac and when the window is fully open, the sidenav occupies its adequate position, yet when it's reduced or I try to open it on another computer the div is not well placed between the header and footer. 我正在使用Mac,当窗口完全打开时,sidenav占据了它的适当位置,但是当它减少或者我试图在另一台计算机上打开它时,div在页眉和页脚之间没有很好的位置。

The following capture shows the issue : 以下捕获显示了该问题:

在此输入图像描述

If you have an idea about what could be the source of the problem I would be grateful to learn from you! 如果您对可能导致问题的原因有所了解,我将不胜感激,向您学习!

There's no need for javascript at all, you could handle this with pure css 根本不需要javascript,你可以使用纯css处理这个问题

 html, body { height: 100%; padding: 0; margin: 0; } .wrapper { display:flex; flex-direction:column; overflow:hidden; height: 100vh; } .wrapper > header { background:#f5f5f5; padding:30px; flex: 0 0 auto; } .wrapper > main { position:relative; flex: 1 1 auto; overflow: hidden; display: flex; } .wrapper > main > .scroller { width: 100%; min-height:100%; overflow:auto; padding:30px; } .wrapper > main > aside { position:absolute; top: 0; right: 0; bottom: 0; width: 320px; color:#eee; background:#000; padding:30px; } .wrapper > footer { background:#f5f5f5; padding:30px; flex: 0 0 auto; } 
 <div class="wrapper"> <header> header </header> <main> <div class="scroller"> main content </div> <aside> sidebar </aside> </main> <footer> footer<br>brrrr<br>brrrrrrrrr </footer> </div> 

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

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