Home >Web Front-end >Front-end Q&A >How to use css margin-top property

How to use css margin-top property

青灯夜游
青灯夜游Original
2019-05-29 12:00:333996browse

css margin-top is used to set the top margin of elements in web pages, for example: margin-top: 50px; negative values ​​are allowed, and all major browsers support the margin-top attribute.

How to use css margin-top property

How to use the css margin-top property?

The margin-top attribute sets the top margin of the element.

Setable attribute values:

● auto: The browser calculates the lower margins.

● Length: Specifies the bottom margin value in specific units, such as pixels, centimeters, etc. The default value is 0px.

● %: Specifies the bottom margin as a percentage of the width of the parent element.

● Inherit: Specifies that the margins should be inherited from the parent element.

Description: This attribute allows negative values.

Note: All major browsers support the margin-top attribute.

css margin-top property example

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"> 
<style>
p.ex1 {margin-top:2cm;}
</style>
</head>
<body>
<p>一个没有指定边距大小的段落。</p>
<p class="ex1">一个2厘米上边距的段落。</p>
<p>一个没有指定边距大小的段落。</p>
</body>
</html>

Rendering:

How to use css margin-top property

The above is the detailed content of How to use css margin-top property. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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