Unfortunately, I am unable to center the elements in the position: absolute
parent.
Here is my code:
.cont-img {
width:400px;
position: relative;
}
.image {
width:400px;
height:400px;
background:black;
}
.desc {
position: absolute;
top:0px;
height:100%;
width:100%;
color:gold;
display:table;
}
.centered-items {
text-align:center;
display:table-cell;
vertical-align: middle;
}
<div class="cont-img">
<div class="image">
</div>
<div class="desc">
<div class="centered-items">
<div class="item1">
asdasd
</div>
<div class="item2">
asdasd
</div>
</div>
</div>
</div>
PS : I also tried the flex method but unfortunately it didn't work for me because the flex makes the elements not display.
All I need is to make the elements under this absolute parent centered vertically and horizontally.