Jump to content
Sign in to follow this  
XHTMLboy

How does margin 0 auto work?

Recommended Posts

Hi all, i just want to know what "margin: 0 auto;" does, all i know is that it's used for centering things. And i know the zero in "margin: 0 auto;" mean's the TOP and BOTTOM. But what does the auto do. What properties does the auto give to the browser to center things? Help would be apperceated as it's on my mind all the time and it's agrivating me now. And sorry for the crap spelling :)

Edited by XHTMLboy

Share this post


Link to post
Share on other sites

I believe thescientist explained that in your other thread....The auto just tells the browser to split up the available space evenly between the left and right side of the element. By available space, I mean any unoccupied horizontal space between the left and right edges of the parent container.

Edited by ShadowMage

Share this post


Link to post
Share on other sites
I believe thescientist explained that in your other thread....The auto just tells the browser to split up the available space evenly between the left and right side of the element. By available space, I mean any unoccupied horizontal space between the left and right edges of the parent container.
Oooh ok i just didn't see the other post so i posted this one before the other post :L, But i get the margin: 0 auto; now thankyou :) Edited by XHTMLboy

Share this post


Link to post
Share on other sites

The left and right margins are set to half of the difference in width between the element and its container. If the container is 1000px, and the element is 500px, then the difference is 500 and each margin is 250.

Share this post


Link to post
Share on other sites

Shadow explained that, but I'll add some more. The browser subtracts the width of the element from the available space and divides it in two. Half goes to the right margin, half to the left margin.EDIT: :) to jsg

Edited by Deirdre's Dad

Share this post


Link to post
Share on other sites
it just does.
Realistically, after you've been developing a while, some things become so automatic that "it just does" is the mindset you live in. One of the reasons I like coming here is that I'm constantly being reminded why a technique does what it does, which is useful on those occasions when it breaks and I need to know how to fix it.

Share this post


Link to post
Share on other sites

i know, i didn't mean to come off as overly sarcastic, even though i did answer the question in his other thread. it's been a heck of long week for me and looks to be a longer weekend. :)

Share this post


Link to post
Share on other sites

No, no. I was saying I feel the same way most of the time. Just that I also appreciate having a forum that makes me remember stuff.

Share this post


Link to post
Share on other sites

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.   Paste as plain text instead

  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.

Loading...
Sign in to follow this  

×
×
  • Create New...