Jump to content

Why do people use 0px? (confused :S)


DarrenReeder

Recommended Posts

Hello, I am a "new" website developer, I learnt HTML and PHP just before christmas and i have now decided to learn CSS because i should of learnt it a long time ago..

 

i am looking at some CSS templates and i am going through some tutorials although ive noticed that people use:

 

margin: 0px;
margin: 0 auto;
padding: 0;

 

alot, but im not sure exactly what these do :S, they seem like they should do nothing, but when i remove them it causes all the text on the templates to go messed up.... any help on what they do exactly would help alot...thanks!

Link to comment
https://forums.phpfreaks.com/topic/190703-why-do-people-use-0px-confused-s/
Share on other sites

In CSS there's something called the box model.  You should do some reading about it, and it will help you understand the relationship and function of border, margin and padding.  In your example, the 2nd margin would override the first, unless that's just an example.

 

margin: 0px; would set the top, left, right and bottom margin of the current element to be 0px. 

 

margin: 0 auto, would set the top and bottom margin to 0, and the left and right to be "auto", which would use whatever built in default the browser provides.

 

 

Browsers have default padding and margin values for elements and not all browsers (or even versions of the same browser) use the same rendering.  By explicitly setting them to 0 the designer is able to know flat-out what the "initial" values are for their design.

 

It just makes life easier.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.