Skip to content

Instantly share code, notes, and snippets.

@anshuraj
Last active June 5, 2018 07:28
Show Gist options
  • Save anshuraj/2955d431abe82e94d7d1195838d2d55d to your computer and use it in GitHub Desktop.
Save anshuraj/2955d431abe82e94d7d1195838d2d55d to your computer and use it in GitHub Desktop.
Center image
<html>
<head>
<title>center image</title>
<link href="style.css">
</head>
<body>
<div class=frame>
<span class="helper"></span><img src="http://via.placeholder.com/300x150" />
</div>
<div class=frame>
<span class="helper"></span><img src="http://via.placeholder.com/150x300"/>
</div>
</body>
</html>
.frame {
height: 200px;
width: 200px;
border: 1px solid red;
white-space: nowrap;
text-align: center;
font: 0/0 a;
margin: 1em 0;
}
.helper {
display: inline-block;
height: 100%;
vertical-align: middle;
}
img {
background: #3A6F9A;
vertical-align: middle;
max-height: 100%;
max-width: 100%;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment