Compare the Difference Between Similar Terms

不同ce Between

Home / Technology / IT / 编程 /不同ce Between Margin and Padding

不同ce Between Margin and Padding

December 12, 2014Posted by管理

Margin vs Padding

不同ce between margin and padding is an important aspect inCSSas margin and padding are two important concepts used inCSSto provide spacing between different items. Padding and margins are not interchangeable and have different purposes so must be used appropriately. The padding is the space between the content and the border of a block. The margin, on the other hand, is the space outside the border of a block. Margin separates blocks from adjacent blocks while the padding separates the border from the content.

What is Padding?

在CSS (Cascading Style Sheets), padding is the space kept between the content and the border. It separates the content of a block from its edge. The padding is transparent and includes the background image or background color of the element, as well. The amount of padding of an element is specified by using the term “padding” in CSS code. For example, to add a 25px padding around the content following code can be used.

div {
width: 300px;
height: 300px;
padding: 25px;
border: 25px solid;
}

If necessary, different padding values can be separately specified for left, right, top, and bottom as well. The following piece of code specifies different padding values for each side.

div {
width: 300px;
height: 300px;
padding-top: 25px;
padding-bottom: 35px;
padding-left: 5px;
padding-right: 10 px;
border: 25px solid;
}

不同ce Between Margin and Padding

What is Margin?

在CSS (Cascading Style Sheets), margin is the space outside the border. It separates a block from other blocks. The margin is also transparent, but a great difference with padding is that the margin does not include background images or background colors applied to the element. The amount of margin in CSS is specified using the term “margin”. The following piece of code applied a 25px margin around the div block.

div {
width: 320px;
height: 320px;
border: 5px solid;
margin: 25px;
}

不同t values can be specified for different sides of the block, as well. The following piece of code applies different margin values for each side.

div {
width: 320px;
height: 320px;
border: 5px solid;
margin-top: 25px;
margin-bottom: 35px;
margin-left: 5px;
margin-right: 10px;
}

What is the difference between Margin and Padding?

• Padding is the space between the border and the content while margin is the space outside the border.

• Padding separates the content of a block from the border. The margin separates one block from the other.

• Padding consists of the background images and background colors applied to content while the margin does not content such.

• Margins of adjacent blocks can overlap while padding does not overlap.

Summary:

Padding vs Margin

Padding is the space inside the border of a block that separates the border from the content. The margin is the spacing outside the border that separates a block from the adjacent blocks. Another difference is that padding includes the background image and background colors applied around the content while margin does not contain them. The margins of adjacent blocks may sometimes overlap when the browser render the page but for padding such thing will not happen.

Images Courtesy:

  1. CSS box modelbyFelix.leg(3.0 CC冲锋队)

Related posts:

不同ce Between HTML and CSS 不同ce Between Class and ID 不同ce Between Integer and Pointer 不同ce Between Conventional Testing and Object Oriented Testing 不同ce Between Overriding and Overloading

Filed Under:编程Tagged With:Cascading Style Sheets,CSS,Margin,margin and padding,Margin and Padding Difference,margin definition,margin meaning,margin means,padding,padding definition,padding meaning,padding means

About the Author:管理

Coming from Engineering cum Human Resource Development background, has over 10 years experience in content developmet and management.

Comments

  1. Tom Sharpsays

    July 13, 2020 at 9:00 pm

    Wow, confusing.

    Reply

留下一个回复Cancel reply

Your email address will not be published.Required fields are marked*

Request Article

Featured Posts

不同ce Between Coronavirus and Cold Symptoms

不同ce Between Coronavirus and Cold Symptoms

不同ce Between Coronavirus and SARS

不同ce Between Coronavirus and SARS

不同ce Between Coronavirus and Influenza

不同ce Between Coronavirus and Influenza

不同ce Between Coronavirus and Covid 19

不同ce Between Coronavirus and Covid 19

You May Like

不同ce Between Steel and Aluminium

不同ce Between Steel and Aluminium

不同ce Between Salicylic Acid and Benzoic Acid

不同ce Between Salicylic Acid and Benzoic Acid

不同ce Between Oboe and Clarinet

不同ce Between Oboe and Clarinet

不同ce Between Apnea and Dyspnea

不同ce Between Apnea and Dyspnea

不同ce Between Rounding and Estimating

Latest Posts

  • What is the Difference Between Kaolinite and Illite
  • What is the Difference Between Axon Hillock and Initial Segment
  • What is the Difference Between Glycolic Acid and Hyaluronic Acid and Retinol
  • What is the Difference Between Strawberry Legs and Keratosis Pilaris
  • What is the Difference Between Type 1 and Type 2 Alveolar Cells
  • What is the Difference Between Hydrodissection and Hydrodelineation
  • Home
  • Vacancies
  • About
  • Request Article
  • Contact Us

Copyright © 2010-2018不同ce Between. All rights reserved.Terms of Useand Privacy Policy:Legal.