Home > Web Front-end > HTML Tutorial > How to fill div with remaining height or width_html/css_WEB-ITnose

How to fill div with remaining height or width_html/css_WEB-ITnose

WBOY
Release: 2016-06-24 12:01:23
Original
2559 people have browsed it

Suppose there is a div1 with div2 and div3 inside. div2 has been laid out with a fixed height. How to make div3 cover the remaining height? Please attach your self-written code, thank you!


Reply to the discussion (solution)

Seeking popularity.



function getdomheight(dom){ //Get the height of a dom
return dom.offsetHeight;
}


var div1 = document .getElementById('div1's id');
var div2 = document.getElementById('div2's id');
var div3 = document.getElementById('div3's id');

div3.style.height = getdomheight(div1) - getdomheight(div2) 'px';

is subtraction

function getdomheight(dom){ //Get the height of a dom
return dom.offsetHeight;
}


var div1 = document.getElementById('div1's id');
var div2 = document.getElementById('div2's id') ;
var div3 = document.getElementById('div3's id');

div3.style.height = getdomheight(div1) - getdomheight(div2) 'px';

That's it Subtraction


Is it possible to use css?




function getdomheight(dom){ //Get the height of a dom
return dom.offsetHeight;
}


var div1 = document.getElementById('div1's id');
var div2 = document.getElementById('div2's id');
var div3 = document.getElementById('div3's id') ');

div3.style.height = getdomheight(div1) - getdomheight(div2) 'px';

is subtraction


Is there any way to achieve this with css? ?

Check out css box layout
In addition, old browsers do not support it

function getdomheight(dom){ //Get a dom Height
return dom.offsetHeight;
}


var div1 = document.getElementById('div1's id');
var div2 = document.getElementById('div2's id') ');
var div3 = document.getElementById('div3's id');

div3.style.height = getdomheight(div1) - getdomheight(div2) 'px';

It’s subtraction


This method doesn’t work, does it not throw an exception?

Use jQuery to get height subtraction, which has good compatibility;
In the example below, the border is only used to check whether the desired effect is achieved. If there is a border in actual application, the border needs to be taken into account when subtracting











Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template