Home > Web Front-end > CSS Tutorial > How to make a div occupy the remaining height of the page?

How to make a div occupy the remaining height of the page?

Mary-Kate Olsen
Release: 2024-11-09 05:30:02
Original
665 people have browsed it

How to make a div occupy the remaining height of the page?

Achieving Optimal Div Height Occupation

When working with web layouts, it's often necessary to have a div occupy the remaining height of the page. Take the following case: two divs, one with a fixed height, and the other intended to fill the remaining space.

<div>
Copy after login

To ensure that div2 occupies the remaining height of the page, an effective solution is to employ absolute positioning:

#div1 {
    width: 100%;
    height: 50px;
    background-color: red; /* Development Only */
}
#div2 {
    width: 100%;
    position: absolute;
    top: 50px;
    bottom: 0;
    background-color: blue; /* Development Only */
}
Copy after login

With this approach, div1 maintains its fixed height, while div2 is positioned absolutely, starting from the bottom of div1 and occupying the remaining vertical space until the bottom of the page, effectively filling the remaining height.

The above is the detailed content of How to make a div occupy the remaining height of the page?. For more information, please follow other related articles on the PHP Chinese website!

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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template