Skip to content

Instantly share code, notes, and snippets.

@JonMidhir
Created October 6, 2012 16:32
Show Gist options
  • Save JonMidhir/3845391 to your computer and use it in GitHub Desktop.
Save JonMidhir/3845391 to your computer and use it in GitHub Desktop.
Margin:auto to Push/Pull and item
/* CSS Hack to push/pull a fixed width element left/right without floating.
Probably common knowledge but it's new to me. */
/* Margin: auto is often used to center one fixed-width element within another, like so */
#element1 {
width: 980px;
}
#child1 {
width: 550px;
margin: 0 auto;
}
/* turns you can also push the element right or left using just one auto and a 0 for the other side
e.g. to pull an element to the right without floating & clearing: */
#element1 {
width: 980px;
}
#child1 {
width: 550px;
margin: 0 0 0 auto;
}
/* handy */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment