When it comes to Flexbox and absolute positioning, there is a few do's and don't's, and in this case, Safari won't center an absolute positioned element the other browsers does.
You can combine Flexbox and transform: translate
, as the latter does not impact the former, and when times comes, where they all behave the same with Flexbox alone, you can just drop the transform
/left
/top
part.
.container {
display: flex;
justify-content: center;
align-items: center;
position: relative;
}
.text {
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%,-50%);
}
<div class='container'>
<div class='text'>
This should be centered
</div>
<img src="https://placehold.it/250x250"/>
</div>
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…