Created
October 24, 2013 16:42
-
-
Save steppefox/7140642 to your computer and use it in GitHub Desktop.
Methods for the placing element at the center
This file contains hidden or 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
| <!-- OLD SCHOOL METHOD FROM 2000 --> | |
| <style> | |
| div.center-2 { position: relative; float: left; left: 50%; margin: 0; padding: 0; z-index:2} | |
| div.center-2 div.center-3 { position: relative; float: left; right: 50%;z-index:2 } | |
| div.center-1 {overflow: hidden;} | |
| </style> | |
| <div class="center-1"><div class="center-2"><div class="center-3"> | |
| ... | |
| </div></div></div> | |
| <!-- Standart method, when you know width element --> | |
| <style> | |
| #target{ | |
| margin: 0 auto; | |
| } | |
| </style> | |
| <!-- Standart method, for absolute element, when you know width of element --> | |
| <style> | |
| #target{ | |
| position:absolute; | |
| width:300px; | |
| left:50%; | |
| margin-left:-150px; | |
| } | |
| </style> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment