简体   繁体   English

根据页面/屏幕高度调整大小

[英]Resize based on page/screen height

My page is divided into left and right divs, the right div has a border left partitioning the two. 我的页面分为左侧和右侧div,右侧div左侧有一个边框,将两者分隔。 if the height of the right box is bigger then left, it works fine. 如果右框的高度大于左框的高度,则工作正常。 However if the left box height is more, then the border is only halfway. 但是,如果左侧框的高度更大,则边框只有一半。

How can i resize the height of the right box based on the height of entire screen so that the border runs all the way to the end. 我如何根据整个屏幕的高度调整右框的高度,以使边框一直延伸到最后。

You can provide height to your right div like, place a id ( like rightDiv ) there if not (in jQuery). 您可以为您的右div提供高度,例如在jQuery中放置一个id(如rightDiv)。

$('#rightDiv').height($(window).height());

if you want to height of your entire document use: 如果要提高整个文档的高度,请使用:

$('#rightDiv').height($(document).height());

$(window).height() will retrun available browser window height. $(window).height()将重新运行浏览器的可用窗口高度。

$(document).height() will retrun document height. $(document).height()将重新运行文档的高度。

or you can make a comparison: 或者您可以进行比较:

var doc = $(document);
var win = $(window);
var maxHeight =  doc.height() > win.height() ? doc.height() : win.height() ;
$('#rightDiv').height(maxHeight);

You have min-height, for animate height you can try: 您具有最小高度,要设置动画高度,可以尝试:

$('#rightDiv').animate( { height : maxHeight}, <duration>);

<duration> is optional, you can provide here 'slow', 'fast', miliseconds <duration>是可选的,您可以在此处提供“慢”,“快”,毫秒

Another solution would be this pure CSS one: http://jsfiddle.net/zgMv5/ 另一种解决方案是使用这种纯CSS: http//jsfiddle.net/zgMv5/
You put around the left and the right div another <div> and use it as CSS table row. 您将左右div放在另一个<div>周围,​​并将其用作CSS表行。 Then the 2 containing <div> will be the same height. 然后,包含2的<div>将具有相同的高度。

<div id="outer">
  <div id="left">This is some text.</div>
  <div id="right">This is some text.</div>
</div>

The corresponding CSS would look like this: 相应的CSS如下所示:

div#outer {
    display:table-row;  }
div#outer > div {
    display:table-cell;  }
div#left  {
    border-right:1px solid red;  }

I am not sure about the compatibility with old browsers... 我不确定与旧浏览器的兼容性...

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

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