Skip to content

Instantly share code, notes, and snippets.

@igorpronin
Created August 15, 2015 14:39
Show Gist options
  • Save igorpronin/bb643d3a55097d42da80 to your computer and use it in GitHub Desktop.
Save igorpronin/bb643d3a55097d42da80 to your computer and use it in GitHub Desktop.
HTML, CSS / Выравнивание элементов по центру по вертикали, горизонтали. Способ 2. Адаптив.
HTML
<div class="wrap">
<div class="content"> </div>
</div>
<div class="wrap">
<img src="http://lorempixel.com/200/200/sports/" width="200" height="200">
</div>
CSS
.wrap {
width: 400px;
height: 400px;
position: relative;
}
.content {
width: 200px;
height: 200px;
position: absolute;
top: 0;
bottom: 0;
right: 0;
left: 0;
margin: auto;
}
.wrap img {
width: 200px;
height: 200px;
position: absolute;
top: 0;
bottom: 0;
right: 0;
left: 0;
margin: auto;
display: block;
/* Для изображений в целях профилактики ставится "display: block", поскольку браузер по умолчанию добавляет к ним небольшую границу, которую лучше удалить */
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment