Skip to content

Instantly share code, notes, and snippets.

@AlexKardone
Created September 14, 2018 08:20
Show Gist options
  • Save AlexKardone/2d06f4e77966d58e1d11042fe9e05627 to your computer and use it in GitHub Desktop.
Save AlexKardone/2d06f4e77966d58e1d11042fe9e05627 to your computer and use it in GitHub Desktop.
Выравнивание по вертикали внутри блока без заданной высоты
https://learn.javascript.ru/css-center
Если центрируются не-блочные элементы, например inline или inline-block, то vertical-align может решить задачу без всяких таблиц.
Правда, понадобится вспомогательный элемент (можно через :before).
Пример:
<style>
.before {
display: inline-block;
height: 100%;
vertical-align: middle;
}
.inner {
display: inline-block;
vertical-align: middle;
}
</style>
<div class="outer" style="height:100px;border:1px solid blue">
<span class="before"></span>
<span class="inner" style="border:1px solid red">
Центрированный<br>Элемент
</span>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment