My CSS skills are still quite new, and I'm currently attempting to vertically align some text within a div. While this question has been asked previously, I've struggled to make any of the proposed solutions work for my particular case, so it seems like there's something simple that I'm overlooking.
I've attempted:
Placing the text within a <p>
tag and using CSS to apply vertical-align: middle;
to the <p>
tag.
Putting the text inside a <p>
tag and adding vertical-align: middle;
in the parent div's CSS.
Using a
<div class="flex-container">
with CSS modifications such as:
.flex-container {
display: flex;
justify-content: center;
align-items: center;
}
As illustrated here: https://jsfiddle.net/dt3kvmdm/
The height of the parent div is not fixed in pixels; instead, it's set as a percentage. While a solution to a similar issue hinted at this being a potential problem, I'm still unclear about it. Ideally, I'd prefer to retain the percentage-based height.
I'd greatly appreciate any suggestions or advice!
Thank you very much!
Sincerely, Nick