Answer the question
In order to leave comments, you need to log in
Why can't text be centered vertically?
Good evening.
HTML:
<body>
<div class="header">
London
Paris
Tokyo
</div>
...
.header {
height: 70px;
background-color: #181818;
color: white;
text-align: center;
vertical-align: middle;
padding: 5px;
}
Answer the question
In order to leave comments, you need to log in
use flex, no perversions with vertical-align and line-height will help for multi-line text.
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
The vertical-align property only works on inline elements or inline boxes and table cells. When applied to non-table cells, it affects the element itself, not its contents.
the parent element must have position:relative; if the child element is centered with position:absolute
In general there are 6 methods
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question