Home > Web Front-end > CSS Tutorial > How to set div height in css

How to set div height in css

青灯夜游
Release: 2023-01-05 16:10:18
Original
5852 people have browsed it

In CSS, you can use the height attribute to set the div height. You only need to add the "height: height value;" style to the div element. The height attribute sets the height of an element, which defines the height of the element's content area, excluding padding, borders, or margins.

How to set div height in css

The operating environment of this tutorial: Windows 7 system, CSS3&&HTML5 version, Dell G3 computer.

css sets div height

In css, you can use the height attribute to set the div height. Code example:

<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<style type="text/css">
			div {
				width: 500px;
				border: 1px solid red;
				margin: 10px 0;
			}
			div.height{
				height:100px;
			}
		</style>
	</head>

	<body>

		<div>
			这是一些文本。 这是一些文本。 这是一些文本。 (默认高度)
		</div>
		<div class="height">
			这是一些文本。 这是一些文本。 这是一些文本。(高度设置为100px)
		</div>
	</body>

</html>
Copy after login

Rendering:

How to set div height in css

##Description:

The height attribute sets the element's high.

Note: The height attribute does not include padding, borders, or margins!

Attribute value:

ValueDescriptionautodefault. The browser will calculate the actual height. Use px, cm and other units to define the height. Based on the percentage height of the block-level object that contains it.
length
%
For more programming-related knowledge, please visit:

Introduction to Programming! !

The above is the detailed content of How to set div height in css. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
css
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