Skip to content

Instantly share code, notes, and snippets.

@ron4stoppable
Created March 28, 2016 07:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ron4stoppable/6fba4de52d85f335c72c to your computer and use it in GitHub Desktop.
Save ron4stoppable/6fba4de52d85f335c72c to your computer and use it in GitHub Desktop.
/*
* Horizontally center a div within a div using CSS
*/
#inner-new {
margin: 0 auto;
}
/*
* If you are targeting IE8+, it might be better to have this instead:
*/
#inner-ie {
display: table;
margin: 0 auto;
}
/*
* If you don't want to set a fixed width on the inner div you could do something like this
*/
#outer {
width: 100%;
text-align: center;
}
#inner {
display: inline-block;
}
/* the last solution works best with padding */
@ron4stoppable
Copy link
Author

Various CSS tricks to align div horizontally inside another div tag.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment