[英]How to get browser's height from CSS
I am using scrollbar function in my div tag. 我在div标签中使用了滚动条功能。
I want to set the scroll bar to my browser height. 我想将滚动条设置为我的浏览器高度。
I am trying to get the value like this. 我试图获得这样的价值。
javascript JavaScript的
<script>
var height = window.innerHeight;
</script>
css code CSS代码
<style>
.kryesore {
overflow-y: scroll;
overflow-y:auto;
height:height-320px ;
}
</style>
here I have created JSFIDDLE code 在这里我创建了JSFIDDLE代码
I want to show the table within the header and footer without browser scrollbar. 我想在没有浏览器滚动条的情况下在页眉和页脚中显示表格。
the scroll bar should show only in the table that is my requirement. 滚动条应仅显示在我的要求表中。
if I get browser window height I will subtract it by 320. then it will fix my issue and the browser windows scroll bar also not shown so that i want to get the javascript value to css. 如果我得到浏览器窗口的高度,我将其减去320。然后它将解决我的问题,浏览器窗口的滚动条也未显示,因此我想将javascript值获取为css。
can any tell me the correct solution. 谁能告诉我正确的解决方案。
You can't reference JS variables through CSS, but you can change CSS with JS. 您无法通过CSS引用JS变量,但可以使用JS更改CSS。
Try: 尝试:
JS JS
document.querySelector('.kryesore').style.height = height;
You can do it via CSS only. 您只能通过CSS做到这一点。 I don't know what is your CSS class for scrollbar, thus I'm using scrollbar
class. 我不知道您的滚动条CSS类是什么,因此我正在使用scrollbar
类。
<style>
.scrollbar {
overflow-y: auto;
height: calc(100vh - 320px);
}
</style>
100vh
is equal to browser's height, calc
function can dynamically calculate such CSS values. 100vh
等于浏览器的高度, calc
函数可以动态计算此类CSS值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.