Home >Web Front-end >JS Tutorial >How to set div height to 100% using js (code)

How to set div height to 100% using js (code)

不言
不言Original
2018-09-17 16:51:542366browse

The content of this article is about how to use js to set the div height to 100% (code). It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

In the development project, some open source bootstrap templates are used for development. When encountering some content parts that need to be replaced, there is often a problem that the height setting 100% cannot take effect. Here, I use js to force the setting. one time.

Idea: js monitors the scaling behavior of the window, and then dynamically obtains the visible size of the browser window. Then if your page has a header and a footer, pinch the head and tail, and what you get is when the content part is 100% The height can be assigned a value.

Code:

    window.onload=function(){  
             changepHeight();  
        }  
        //当浏览器窗口大小改变时,设置显示内容的高度  
        window.onresize=function(){  
             changepHeight();  
        }  
        function changepHeight(){               
            var h = document.documentElement.clientHeight;//获取页面可见高度  
            document.getElementById("framep").style.height=h-102+"px";//掐头去尾,减去100px  
    }

The above is the detailed content of How to set div height to 100% using js (code). For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn