Skip to content

Instantly share code, notes, and snippets.

@codetrail
Created September 28, 2012 05:48
Show Gist options
  • Save codetrail/3798128 to your computer and use it in GitHub Desktop.
Save codetrail/3798128 to your computer and use it in GitHub Desktop.
CSS: Absolute Center Image
<!DOCTYPE HTML>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<title></title>
<style type="text/css">
/*CSS background-image Technique*/
html {
width: 100%;
height: 100%;
background: url(logo.png) center center no-repeat;
}
/*CSS + Inline Image Technique*/
img {
position: absolute;
top: 50%;
left: 50%;
width: 500px;
height: 500px;
margin-top: -250px; /* Half the height */
margin-left: -250px; /* Half the width */
}
/*Table technique*/
html, body, #wrapper {
height:100%;
width: 100%;
margin: 0;
padding: 0;
border: 0;
}
#wrapper td {
vertical-align: middle;
text-align: center;
}
</style>
</head>
<body>
<table id="wrapper">
<tr>
<td><img src="logo.png" alt="" /></td>
</tr>
</table>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment