Home >Web Front-end >CSS Tutorial >How Can I Center Text Over an Image Using CSS Positioning Instead of Flexbox?
In this guide, we will explore an alternative approach to centering text over an image using pure CSS positioning properties instead of Flexbox.
Positioning Properties:
.height-100vh { position: relative; } .text { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); }
Example Usage:
<section class="height-100vh center-aligned"> <img class="background-image" src="image.jpg" /> <div class="text">SOME TEXT</div> </section>
By implementing these positioning properties, you can effectively center text over an image without relying on Flexbox. This approach offers a simple and straightforward solution for this common layout task.
The above is the detailed content of How Can I Center Text Over an Image Using CSS Positioning Instead of Flexbox?. For more information, please follow other related articles on the PHP Chinese website!