Vertical align table-cell don’t work with position absolute

Everything works as expected until I add “position: absolute”. Now it
can’t place my content in the middle any more? Why not?

position: absolute forces display: block, read number two here.

As for a workaround, I think you’ll have to wrap it in another element:

<div class="table-cell-wrapper">
    <div class="table-cell">
        My text, should be align middle
    </div>
</div>

.table-cell-wrapper {
    position: absolute;
}
.table-cell {
    height: 200px;
    width: 200px;
    vertical-align: middle;
    background: #eee;
    display: table-cell;
}

Leave a Comment