Skip to content

Instantly share code, notes, and snippets.

@TechFounder
Last active August 29, 2015 13:57
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 TechFounder/9668187 to your computer and use it in GitHub Desktop.
Save TechFounder/9668187 to your computer and use it in GitHub Desktop.
You want a way to center any object to the middle of the page (horizontal centering)?
<div id="first">
<div id="second">
Item you want centered
</div>
</div>
for example:
<a href="mailto:info@email.com?Subject=Web%20Page" target="_top" id="first">
<img src="photo.png" alt="photo">
</a>
#first {
position: absolute;
left: 50%;
}
#second {
position: relative;
left: -50%;
}
or, from the example:
#first {
position: absolute;
left: 50%;
}
#first img {
position: relative;
left: -50%;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment