Created
October 6, 2012 16:32
-
-
Save JonMidhir/3845391 to your computer and use it in GitHub Desktop.
Margin:auto to Push/Pull and item
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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