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
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.

 

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.