Home > Web Front-end > CSS Tutorial > How Can I Set a Div's Height to 100% While Maintaining a DOCTYPE?

How Can I Set a Div's Height to 100% While Maintaining a DOCTYPE?

Barbara Streisand
Release: 2024-12-27 19:59:15
Original
162 people have browsed it

How Can I Set a Div's Height to 100% While Maintaining a DOCTYPE?

CSS Height Property, Percentage Values, and DOCTYPE

Setting Div Height to 100%

To fill the div with 100% height without removing the DOCTYPE, declare a height on the root element:

Quirks Mode and Percentage Heights

Removing the DOCTYPE switches the browser from standards mode to quirks mode. In quirks mode, percentage heights of child elements are measured relative to the viewport if the parent element has height: auto. In standards mode, they are treated as height: auto.

TL;DR

Always include a DOCTYPE to render the document in standards mode. Use the following DOCTYPE:

The above is the detailed content of How Can I Set a Div's Height to 100% While Maintaining a DOCTYPE?. 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