Home > Web Front-end > HTML Tutorial > How to set the top margin in html

How to set the top margin in html

青灯夜游
Release: 2021-11-01 17:16:25
Original
17243 people have browsed it

htmlHow to set the top margin: 1. Use the padding-top attribute to set the top padding, the syntax is "padding-top:margin value;"; 2. Use the margin-top attribute to set the top margin, Syntax "margin-top:margin value;".

How to set the top margin in html

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

htmlSet the top margin

How to set the top margin in html

Method 1: Set the top margin

Padding refers to the space between the element border and the element content. We can use the padding-top attribute to set the top padding of an element.

Example:

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<style type="text/css">
div{
border: 1px solid red;
}
.box{
padding-top: 20px;
}
</style>
</head>
<body>
<div>测试文本</div>
<div>测试文本</div>
</body>
</html>
Copy after login

Rendering:

How to set the top margin in html

##Method 2: Set top margin

Margin refers to the space around the element. We can use the margin-top attribute to set the top margin of an element.

Example:

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<style type="text/css">
div{
border: 1px solid red;
}
.box{
margin-top: 20px;
}
</style>
</head>
<body>
<div>测试文本</div>
<div>测试文本</div>
</body>
</html>
Copy after login
Rendering:

How to set the top margin in html

Recommended tutorial: "

html video tutorial"

The above is the detailed content of How to set the top margin in html. 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