When I should use Margin and Padding in CSS ?

hoangvu

New member
Joined
Jun 6, 2012
Messages
1,889
Points
0
It's difficult for me to use padding and margin in Css, are they different ?
Anyone know about When I should use Margin and Padding in CSS and any Tips ?

Thanks
 

Frank

New member
Joined
Jul 7, 2012
Messages
40
Points
0
Use margin for boxes contain ojeccts ( texts, images..) and using padding for those ojects into boxes
 

unni6849

New member
Joined
Oct 5, 2012
Messages
17
Points
0
Margin and Padding are important tools in the Dreamweaver.You should add margin in order to centralize the web pages and padding is used to align the text element in the CSS document.
 

leszek

New member
Joined
Oct 27, 2012
Messages
6
Points
0
here you will find all info that you need

w3schools.com/css/css_margin.asp

w3schools.com/css/css_padding.asp
 

telma

New member
Joined
Feb 9, 2013
Messages
4
Points
0
Hello..
yes you are right friend.w3school.com is the most easy site where we learn about css.Thank you for the posting.
 

MechanicWeb-shoss

New member
Joined
Apr 11, 2016
Messages
20
Points
0
It's difficult for me to use padding and margin in Css, are they different ?
Anyone know about When I should use Margin and Padding in CSS and any Tips ?

Thanks
Margin adds a gap outside of an element
Padding adds a gap inside of an element

For example, you have a div element with border and background color. If you add padding to it, the background color and border will be displayed around and through the gap. However, if you add margin to the div, the border and background color will not be displayed around the gap but displayed inside.

Hope that helps.
 

PenguinManiac

New member
Joined
Jun 27, 2017
Messages
200
Points
0
PenguinManiac
Sums it up nicely.
Since you asked about usage, I'd also add that margins are subject to margin collapse: so, when two vertical margins overlap, under certain circumstances the larger margin might override the other. This is more common than it seems, so keep this in mind when you're facing spacing issues while using margins.
 

ccwoods03

New member
Joined
Aug 6, 2017
Messages
1
Points
0
They both are great tools to know or learn when it comes to web design and development. They add spaces between your items such as text, images, and buttons. They are a little different in how they work, but overall they practically do the same thing.
 
Older threads
Replies
1
Views
4,129
Replies
2
Views
4,478
Replies
6
Views
6,107
Replies
0
Views
40,649
Newer threads
Replies
4
Views
3,053
Replies
2
Views
2,468
Replies
1
Views
1,910
Replies
1
Views
2,479
Replies
3
Views
2,035
Latest threads
Replies
0
Views
76
Replies
4
Views
114
Replies
1
Views
148
Replies
1
Views
98
Recommended threads
Replies
5
Views
4,202
Replies
0
Views
1,793
Replies
5
Views
1,986
Replies
0
Views
3,075

Referral contests

Referral link for :

Sponsors

Latest Blog ArticlesMost Viewed Threads

Popular tags

You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an alternative browser.

Top