What does CSS margin do?
First of all, we need to know what margin means. The margin attribute is the abbreviation attribute of CSS for setting all margin attributes in one statement. It is an attribute used to control the distance between each element. They are transparent and invisible.
The margin attribute includes margin left: the distance from the left element block (set the distance from the left inner margin ); margin top: the distance from the top (top) element block (set the distance from the top element block) distance); margin right: distance from the right element block (set the block distance from the right element); margin bottom: distance from the bottom element block (set the distance from the lower (lower) element block). Its two-dimensional construction diagram can be seen in the CSS attribute two-dimensional diagram.
margin left usage: margin-left:10px; This means 10 pixels from the left element block, which can be followed by a percentage such as (margin-left:10%; 10% from the left element block) distance) css margin-left tutorial;
margin right usage: margin-right:10px; This means that the block distance from the right element is 10 pixels, which can be followed by a percentage such as (margin-right: 10%; 10% of the distance from the right element block);
margin top usage: margin-top:10px; This means 10 pixels from the top element block, which can be followed by the percentage, such as (margin-top:10%; 10% distance from the top element block) css margin-top;
margin bottom usage: margin-bottom:10px; This means distance from the lower edge The element block distance is 10 pixels, which can be followed by a percentage such as (margin-bottom:10%; 10% distance from the bottom element block) css margin-bottom;
Pay attention to the link "-" in the middle of the margin, set Use " : " to assign a distance value, end with " ; ", and use all lowercase half-width letters.
If you need to set the margin value for both the left and right sides, you can do it in abbreviation to optimize css.
For example, the abbreviation is:
margin:10px; It means that the distance between the top, bottom, left and right element blocks is 10px (10 pixels), which is equal to margin-top:10px; margin-bottom:10px; margin-left :10px; margin-right:10px; abbreviation for the same effect;
margin:5px 10px; meaning that the distance between the upper and lower element blocks is 5px, and the distance between the left and right element blocks is 10px, which is equal to margin-top:5px; margin-bottom :5px; margin-left:10px; margin-right:10px; Abbreviation for the same effect;
margin:5px 6px 7px; meaning the distance between the upper element block is 5px, the distance between the lower element block is 7PX, and the distance between the left and right element blocks is 6px, equal to margin-top:5px; margin-bottom:7px; margin-left:6px; margin-right:6px; abbreviation for the same effect;
margin:5px 6px 7px 8px; meaning the element block is 5px , the distance between the right element block is 6px, the distance between the lower element block is 7px, and the distance between the left element block is 8px, which is equal to margin-top:5px; margin-right:6px; margin-bottom:7px; margin-right:8px; abbreviation for the same effect ;
There are so many ways to use the margin attribute of CSS. Friends who need it can save it. Please also continue to pay attention to other updates on this site.
Related reading:
The above is the detailed content of What does CSS margin do?. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Using Bootstrap in Vue.js is divided into five steps: Install Bootstrap. Import Bootstrap in main.js. Use the Bootstrap component directly in the template. Optional: Custom style. Optional: Use plug-ins.

HTML defines the web structure, CSS is responsible for style and layout, and JavaScript gives dynamic interaction. The three perform their duties in web development and jointly build a colorful website.

WebdevelopmentreliesonHTML,CSS,andJavaScript:1)HTMLstructurescontent,2)CSSstylesit,and3)JavaScriptaddsinteractivity,formingthebasisofmodernwebexperiences.

There are two ways to create a Bootstrap split line: using the tag, which creates a horizontal split line. Use the CSS border property to create custom style split lines.

There are several ways to insert images in Bootstrap: insert images directly, using the HTML img tag. With the Bootstrap image component, you can provide responsive images and more styles. Set the image size, use the img-fluid class to make the image adaptable. Set the border, using the img-bordered class. Set the rounded corners and use the img-rounded class. Set the shadow, use the shadow class. Resize and position the image, using CSS style. Using the background image, use the background-image CSS property.

To set up the Bootstrap framework, you need to follow these steps: 1. Reference the Bootstrap file via CDN; 2. Download and host the file on your own server; 3. Include the Bootstrap file in HTML; 4. Compile Sass/Less as needed; 5. Import a custom file (optional). Once setup is complete, you can use Bootstrap's grid systems, components, and styles to create responsive websites and applications.

How to use the Bootstrap button? Introduce Bootstrap CSS to create button elements and add Bootstrap button class to add button text

To adjust the size of elements in Bootstrap, you can use the dimension class, which includes: adjusting width: .col-, .w-, .mw-adjust height: .h-, .min-h-, .max-h-
