40
I’m trying to center vertically the content of an element that has position: absolute
.
I was able to move the content from half down container, however, from half up the space is "left".
How can I solve this just by using css?
Here’s my code so far:
.container {
position: absolute;
width: 100%;
height: 100%;
background: #ccc;
}
.content {
position: absolute;
top: 50%;
left: 25%;
width: 50%;
text-align: center;
}
<div class="container">
<div class="content">
<h1>Conteúdo</h1>
<p>Subtítulo</p>
</div>
</div>
The idea is that the element .container
overlap the parent element, as if it were an indicator of loading on top of only one element on the page.
It is really necessary that the element have absolute position? Or just your container?
– mgibsonbr
I updated the question with a better description of the objective.
– gustavohenke