How to set the width of html div

青灯夜游
Release: 2021-12-13 14:59:28
Original
24396 people have browsed it

html How to set the width of div: 1. Add the "width: width value;" style to the div element to set a fixed width; 2. Add the "min-width: width value;" style to the div element to set the minimum width ;3. Add the "max-width:width value;" style to the div element to set the maximum width.

How to set the width of html div

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

html div setting width

1. Use the width attribute

width attribute to set the element width. (Note: The width attribute does not include padding, borders and margins!)

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<style>
			div{
				border: 1px solid red;
			}
		</style>
	</head>
	<body>
		<div>默认div宽度是自适应,由视口决定</div>
		<div style="width: 200px;">设置div宽度为200px</div>
	</body>
</html>
Copy after login

How to set the width of html div

2. Use the min-width attribute

## The #min-width attribute sets the minimum width of an element.

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<style>
			div{
				border: 1px solid red;
			}
		</style>
	</head>
	<body>
		<div>默认div宽度是自适应,由视口决定</div>
		<div style="min-width: 200px;">设置div最小宽度为200px</div>
	</body>
</html>
Copy after login

How to set the width of html div

3. Use the max-width attribute

max-width attribute to set the maximum width of the element.

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<style>
			div{
				border: 1px solid red;
			}
		</style>
	</head>
	<body>
		<div>默认div宽度是自适应,由视口决定</div>
		<div style="max-width: 500px;">设置div最大宽度为500px</div>
	</body>
</html>
Copy after login

How to set the width of html div

Recommended tutorial: "

html video tutorial"

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

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