DarrenReeder Posted February 2, 2010 Share Posted February 2, 2010 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! Quote Link to comment https://forums.phpfreaks.com/topic/190703-why-do-people-use-0px-confused-s/ Share on other sites More sharing options...
gizmola Posted February 2, 2010 Share Posted February 2, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/190703-why-do-people-use-0px-confused-s/#findComment-1005688 Share on other sites More sharing options...
DarrenReeder Posted February 2, 2010 Author Share Posted February 2, 2010 but wouldnt Margin: 0px; be the same as putting nothing there, because 0px is nothing :/ thats what is confusing Quote Link to comment https://forums.phpfreaks.com/topic/190703-why-do-people-use-0px-confused-s/#findComment-1005692 Share on other sites More sharing options...
roopurt18 Posted February 2, 2010 Share Posted February 2, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/190703-why-do-people-use-0px-confused-s/#findComment-1005695 Share on other sites More sharing options...
DarrenReeder Posted February 2, 2010 Author Share Posted February 2, 2010 oh i see, it just makes sure its a constant layout throughout ALL browsers? Quote Link to comment https://forums.phpfreaks.com/topic/190703-why-do-people-use-0px-confused-s/#findComment-1005696 Share on other sites More sharing options...
akitchin Posted February 2, 2010 Share Posted February 2, 2010 precisely - otherwise, anything left unspecified simply assumes the browser's default values. Quote Link to comment https://forums.phpfreaks.com/topic/190703-why-do-people-use-0px-confused-s/#findComment-1005701 Share on other sites More sharing options...
gizmola Posted February 2, 2010 Share Posted February 2, 2010 You should also google Eric Myers css reset. Quote Link to comment https://forums.phpfreaks.com/topic/190703-why-do-people-use-0px-confused-s/#findComment-1005704 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.