Home >Web Front-end >CSS Tutorial >How to write the top margin in css

How to write the top margin in css

醉折花枝作酒筹
醉折花枝作酒筹Original
2021-07-26 15:10:583618browse

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.

How to write the top margin in css

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

How to write the top margin in css

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!

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