Как выставить блок по центру экрана?
У меня примерно вот такой случай, но не могу понять, как выставить text по центру экрана
.container{
position: relative;
width: 100%;
height: 100%;
}
.container .block {
position: absolute;
top: 50%;
left: 50%;
margin-right: 50%;
transform: translate(-50%,-50%);
}
.container .block span {
color: #000;
font-size: 35px;
}
<div class='container'>
<div class='block'>
<span>TEXT</span>
</div>
</div>
Ответы (3 шт):
Автор решения: Вадим
→ Ссылка
.container{
position: relative;
width: 100%;
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
}
.container .block span {
color: #000;
font-size: 35px;
}
<div class='container'>
<div class='block'>
<span>TEXT</span>
</div>
</div>
Автор решения: vantal
→ Ссылка
У вас проблемы с самым контейнером container. Если хотите чтоб он был равен высоте экрана, задайте ему height: 100vh вместо height: 100%
Автор решения: soledar10
→ Ссылка
Еще как вариант, добавить
html,
body{
height: 100%;
}
html,
body{
height: 100%;
}
body{
margin: 0;
}
.container{
position: relative;
width: 100%;
height: 100%;
}
.container .block {
position: absolute;
top: 50%;
left: 50%;
margin-right: 50%;
transform: translate(-50%,-50%);
}
.container .block span {
color: #000;
font-size: 35px;
}
<div class='container'>
<div class='block'>
<span>TEXT</span>
</div>
</div>