Sujan Khadka Posted on Dec 5, 2019 What does auto do in margin:0 auto? #css #beginners #javascript #php Top comments (2) Subscribe Collapse Expand Richard JP Le Guen Richard JP Le Guen Richard JP Le Guen Follow Location Montreal, Quebec Education BEng, Concordia University (Montreal) Work Software Developer at Broadsign Joined Dec 5, 2019 • Dec 5 '19 • Edited on Dec 5 • Edited Dropdown menu Copy link Hide Looking at the MDN article for CSS margin it says: When two values are specified, the first margin applies to the top and bottom, the second to the left and right. Citation: developer.mozilla.org/en-US/docs/W... So margin: 0 auto is the same as the following 4 properties: margin-top: 0; margin-right: auto; margin-bottom: 0; margin-left: auto; When margin-left and margin-right are both auto that will usually center-align a Block Level Element, like a <div>. Collapse Expand Sujan Khadka Sujan Khadka Sujan Khadka Follow Software developer👨🏻💻| Location Queensland, Australia Education Master of Information Systems (MISP) Work Dev Joined Nov 15, 2019 • Dec 5 '19 Dropdown menu Copy link Hide Thanks! Code of Conduct • Report abuse For further actions, you may consider blocking this person and/or reporting abuse
Top comments (2)
Looking at the MDN article for CSS
margin
it says:Citation: developer.mozilla.org/en-US/docs/W...
So
margin: 0 auto
is the same as the following 4 properties:When
margin-left
andmargin-right
are bothauto
that will usually center-align a Block Level Element, like a<div>
.Thanks!