Get the App
SLTechnology News&Howtos  ›  Development  › 

What does margin mean?

Shulou Source: shulou.com Published: 2022-06-02 13:58:37 11月07日 Update

Today, I would like to talk to you about the meaning of margin, many people may not know much about it. In order to make you understand better, the editor summed up the following content for you. I hope you can get something according to this article.

Let's focus on the use of the CSS margin attribute, which sets the width of all outer margins of an element, or sets the width of the outer margins of each edge.

CSS margin attribute

Define

The margin property is an abbreviated property used to set all four outer margins in a declaration.

Note: negative values are allowed.

Inheritance: No

Description

This shorthand property sets the width of all the outer margins of an element, or sets the width of the outer margins on each side.

The vertical adjacent outer margins of block-level elements are merged, while inline elements do not actually occupy the upper and lower outer margins. The left and right margins of inline elements are not merged. Similarly, the outer margins of floating elements are not merged. A negative margin value is allowed, but be careful when using it.

JavaScript syntax

The CSS attribute can also be changed dynamically through a JavaScript.

Script syntax:

Object.style.margin= "100px"

Examples

All four margins are 10px:

H2 {margin: 10px} top and bottom margins are 10px, and the left and right margins are 2% of the width of the parent element:

H2 {margin: 10px 2%} the top margin is 10px, the left and right margins are 2% of the parent element width, and the bottom margin is-10px:

H2 {margin: 10px 2%-10px} Top margin is 10px, right margin is 2% of the parent element width, bottom margin is-10px, and the left margin is set by the browser:

H2 {margin: 10px 2%-10px auto}

Possible value

After reading the above, do you have any further understanding of what margin means? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.

Tags: Elements attributes width content right bottom shorthand meaning grammar up and down examples dynamic actual actually more comments browsers knowledge articles inheritance Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Xiaomi Microsoft Shulou Technology macOS NVidia