I have encountered a situation where I need to center text within a div that also has an aspect ratio. Since the aspect-ratio
property is not supported by major browsers like Safari, I am looking for an alternative solution.
Here is my current code:
.aspect-ratio-div{
background-color: #f2f2f7;
position: relative;
width: 100%;
padding-top: 33.33%;
}
.text{
position: absolute;
top: 0;
left: 0;
bottom: 0;
right: 0;
text-align: center;
font-size: 20px;
color: white;
}
<html>
<div class="aspect-ratio-div">
<label>This is some centered text</label>
</div>
</html>
This method works well for images, but how can I achieve the same effect for text?
I want the output to resemble this image: https://i.sstatic.net/Kjm9M.png
The white space should maintain a 1:3 ratio, with the text always centered within it.
Any suggestions for a better approach?
I found the solution I needed, thank you!