Get the App
SLTechnology News&Howtos  ›  Development  › 

How to set margin in css

Shulou Source: shulou.com Published: 2022-05-31 17:49:19 09月12日 Update

This article mainly explains "how to set margin in css". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to set margin in css".

Concept

1. Margin is an attribute in the CSS cascading style sheet that defines the extent of the white space around the border of the element.

Grammar

Margin:auto/length

Parameters.

Auto: value is set to the value of the relative edge

Length: length value consisting of floating-point numbers and unit identifiers | percentage. The percentage is based on the height of the parent object.

Matters needing attention

2. If all four parameter values are provided, they will act on the four sides in the order of top, right, bottom, and left.

If only one is provided, it will be used on all four sides.

If two are provided, the first is for top and bottom, and the second is for left and right.

If three are provided, the first is for the top, the second for the left and right, and the third for the bottom.

Example

The vertically adjacent outer margins of block-level elements are merged.

Margin div {margin: 20px; color: # fff;} .top {background: green;} .bottom {background: orange } margin: 20px margin: 20px Thank you for your reading. The above is the content of "how to set margin in css". After the study of this article, I believe you have a deeper understanding of how to set up margin in css, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Tags: Learning three elements content parameters four sides percentage percentage two use events functions regions units instances objects that is attributes ideas situations Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno OPPO Reno MySQL Shulou Tech Info Redmi Xiaomi