Home Web Front-end HTML Tutorial The difference between padding and margin in CSS

The difference between padding and margin in CSS

Jun 22, 2017 am 10:53 AM
css margin padding the difference

In CSS, margin refers to the distance from its own frame to the border of another container, which is the distance outside the container. In CSS, padding refers to the distance between its own frame and the border of another container inside itself, which is the distance within the container.

The following explains the common usage of padding and margin

1. padding

1. Grammar structure

(1)padding-left:10px; left padding

(2)padding-right:10px; right padding

(3)padding- top:10px; top padding

(4)padding-bottom:10px; bottom padding

(5)padding:10px; unified padding on all four sides

(6)padding:10px 20px; top, bottom, left and right padding

(7)padding:10px 20px 30px; top, left, and bottom padding

(8)padding:10px 20px 30px 40px; top, right, bottom, left padding

2. Possible values ​​

(1) length specifies the padding in specific units Length

(2) % The length of the padding based on the width of the parent element

(3) auto The browser calculates the padding

(4) inherit specifies that it should Inherit padding from parent element

3. Browser compatibility issues

(1) All browsers support the padding attribute

(2) Any version of IE does not support the attribute value "inherit"

2. margin

1. Syntax structure

(1)margin-left:10px; left margin

(2)margin-right:10px; right margin

(3)margin-top:10px; top Margin

(4) margin-bottom: 10px; bottom margin

(5) margin: 10px; unified margin on all four sides

(6) margin: 10px 20px ; Top, bottom, left and right margins

(7) margin: 10px 20px 30px; Top, left, and bottom margins

(8) margin: 10px 20px 30px 40px; top, right, bottom, Left margin

2. Possible values ​​

(1) length specifies the margin length in specific units

(2)% The length of the margin based on the width of the parent element

(3) auto The browser calculates the margin

(4) inherit specifies that the margin should be inherited from the parent element

3. Browser compatibility issues

(1) All browsers support the margin attribute

(2) Any version of IE does not support the attribute value" inherit”

3. The difference between margin and padding is represented by the diagram

The above is the detailed content of The difference between padding and margin in CSS. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
Two Point Museum: All Exhibits And Where To Find Them
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to use the locally installed 'Jingnan Mai Round Body' on a web page and solve the display problem? How to use the locally installed 'Jingnan Mai Round Body' on a web page and solve the display problem? Apr 05, 2025 pm 02:06 PM

How to use locally installed font files on web pages In web development, users may want to use specific fonts installed on their computers to enhance the network...

How to customize resize symbols through CSS to match background color? How to customize resize symbols through CSS to match background color? Apr 05, 2025 pm 02:09 PM

How to customize resize symbols with CSS to match background color? In web design, the details of the user experience can often significantly improve the overall effect. For example...

In Angular app: How to change icon color by hovering over? In Angular app: How to change icon color by hovering over? Apr 05, 2025 pm 02:15 PM

In Angular app, how to change the color of the icon when the mouse is hovered over it? Many developers will encounter needs when building applications using Angular...

How to use CSS to efficiently achieve various concave effects? How to use CSS to efficiently achieve various concave effects? Apr 05, 2025 pm 02:18 PM

Many ways to achieve concave effects in CSS Many developers have encountered the need to achieve concave effects in web pages. Recently, a developer mentioned on the forum...

How to achieve perfect alignment of text bottoms of different font sizes and fonts with CSS? How to achieve perfect alignment of text bottoms of different font sizes and fonts with CSS? Apr 05, 2025 pm 01:48 PM

The problem of alignment at the bottom of CSS text: The vertical arrangement of different font sizes and fonts in CSS style design, you often encounter the need to align different font sizes and...

How to implement a front-end progress bar with ring effect and mouse prompt information? How to implement a front-end progress bar with ring effect and mouse prompt information? Apr 05, 2025 pm 01:54 PM

Discussion on the implementation method of front-end progress bar In front-end development, implementing a progress bar seems simple, but to meet the precise requirements of the design draft, you may encounter a...

How to properly introduce index.css file of Element UI and avoid style loading failures? How to properly introduce index.css file of Element UI and avoid style loading failures? Apr 05, 2025 pm 02:33 PM

Best practices about the introduction of ElementUI style files Many developers are using Element...

How to solve the problem of page scrolling after the soft keyboard of the mobile Edge browser pops up? How to solve the problem of page scrolling after the soft keyboard of the mobile Edge browser pops up? Apr 05, 2025 pm 02:57 PM

Regarding the Edge browser input method, page height and scrolling after the keyboard pops up. When using the Edge browser on your mobile phone, the page often encounters this problem: �...

See all articles