Адаптивное центрированное изображение
by Евгений
HTML
<a href="http://www.dejurka.ru/css/responsive-centered-image-css/">источник</a>
<img src="http://lorempixel.com/600/450/" class="ri" />
CSS
body {
font-family: sans-serif;
font-size: 100%;
margin: 10px;
color: #ddd;
background-color: #333;
}
a { color: #fff; }
img.ri {
position: absolute;
max-width: 80%;
top: 10%;
left: 10%;
border-radius: 3px;
box-shadow: 0 3px 6px rgba(0,0,0,0.9);
}
img.ri:empty {
top: 50%;
left: 50%;
-webkit-transform: translate(-50%, -50%);
-moz-transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
-o-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
}
@media screen and (orientation: portrait) {
img.ri {
max-width: 90%;
}
}
@media screen and (orientation: landscape) {
img.ri {
max-height: 90%;
}
}