[英]How to set side bar between two div and it should fit in the any browser window based on resize
I am having two grid one div is header another one is footer between the two grid, I am using sidebar in left side. 我有两个网格,一个div是页眉,另一个是两个网格之间的页脚,我在左侧使用侧边栏。
Here is my JavaScript code 这是我的JavaScript代码
function resize()
{
var heights = window.innerHeight;
document.getElementById("left").style.height = heights + "px";
}
resize();
window.onresize = function() {
resize();
};
I want to show this full content with in the page without show any browser scroll bar. 我想在页面中显示此完整内容,而不显示任何浏览器滚动条。
Here is my demo 这是我的演示
Using Jquery: 使用jQuery:
You take the browser screen height 您以浏览器的屏幕高度为准
$(window).height()
& then reduce the height of header & footer 然后降低页眉和页脚的高度
$(window).height() - $('header').outerHeight() - $('footer').outerHeight()
Using JS 使用JS
window.innerWidth - document.getElementById('header').offsetHeight - document.getElementById('footer').offsetHeight;
Instead of offsetHeight you can also use clientHeight. 除了offsetHeight,您还可以使用clientHeight。 Difference is: 区别是:
clientHeight
includes padding. clientHeight
包括填充。
offsetHeight
includes padding, scrollBar and borders. offsetHeight
包括填充,scrollBar和边框。
Updated 更新
Update your function resize()
as: 将您的function resize()
更新为:
document.getElementById('inner').style.maxHeight = window.innerWidth - document.getElementById('header').offsetHeight - document.getElementById('footer').offsetHeight;
You can use pure CSS: there are a few ways to determine the behavior of CSS to adjust to screen size. 您可以使用纯CSS:有几种方法可以确定CSS的行为以适应屏幕尺寸。 I think that a good method for this is to use the viewport units: vw
and vh
, this will let you achieve responsive design easily... 我认为为此的一个好方法是使用视口单位: vw
和vh
,这将使您轻松实现响应式设计...
vw stands for "viewport width" and vh is for "viewport height". vw代表“视口宽度”,而vh代表“视口高度”。 and, you can use it with CSS like in this example: 并且,您可以将其与CSS一起使用,例如以下示例:
div {
width: 100vw;
height: 100vh;
}
This guide may be helpful to understand this method better... 本指南可能有助于更好地了解此方法...
You can also set px for pixels and other CSS sizing units instead of % and also use vmin and vmax for minimum and maximum size adjustment, or just use min-height/width like in this example: 您还可以为像素和其他CSS大小调整单位设置px而不是% ,还可以使用vmin和vmax进行最小和最大大小调整,或者仅使用min-height / width,例如本示例:
.sidebar {
min-width: 30%;
min-height: 30%;
}
Another more modern way is to do it with flexbox ... 另一种更现代的方法是使用flexbox ...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.