【工作记录】解决溢出div自适应的高度问题

今天解决的一个问题,记录一下,先用文字记录下,有时间再用代码还原下。

响应式网站中,导航div包含的点击按钮下方出现菜单,无法控制高度(max-height控制百分比不行),后用js实现。是否不用js可以有更好方法?(之后补充)

js代码如下

function redirectpage() {
//var h1=document.getElementById("div_nav_top").height;/*页面上方顶部导航条div(z-index:2000),不知道为何不能获取其高度*/
//var h2=document.getElementById("div_nav_bottom").height;/*页面下方方顶部导航条div(z-index:2000),不知道为何不能获取其高度*/
if (window.innerHeight)
var winHeight = window.innerHeight;/*获取浏览器高度*/
else if ((document.body) && (document.body.clientHeight))
winHeight = document.body.clientHeight;
//var h_plus=130+'px';
var h_list=winHeight-130+'px';/*js计算高度的格式*/
//alert("h_list"+h_list);
document.getElementById("drop_down_h").style.maxHeight = h_list;
//alert("winHeight:"+winHeight);
//alert("下拉菜单的宽度:"+document.getElementById("drop_down_h").style.maxHeight);
}

原文地址:https://www.cnblogs.com/monozxy/p/5055951.html