Home >Web Front-end >CSS Tutorial >How to write the top margin in css
In CSS, you can use the margin-top attribute to set the top margin. You only need to set the "margin-top: value unit;" style to the element. The margin-top property sets the top margin of the element, allowing negative values.
The operating environment of this tutorial: Windows 7 system, CSS3&&HTML5 version, Dell G3 computer.
margin shorthand property sets all margin properties in one declaration. This attribute can have 1 to 4 values.
Description
This shorthand property sets the width of all margins of an element, or sets the width of margins on each side.
The vertically adjacent margins of block-level elements will be merged, while inline elements will not actually occupy the top and bottom margins. The left and right margins of inline elements are not merged. Likewise, the margins of floated elements are not merged. It is allowed to specify negative margin values, but use caution when using them.
Note: Negative values are allowed.
The margin-top attribute sets the top margin of the element.
Example
<html> <head> <style type="text/css"> p.topmargin { margin-top: 5cm; } </style> </head> <body> <p>这个段落没有指定外边距。</p> <p class="topmargin">这个段落带有指定的上外边距。</p> </body> </html>
Effect
Recommended learning: css video tutorial
The above is the detailed content of How to write the top margin in css. For more information, please follow other related articles on the PHP Chinese website!