I'm struggling to center a block of text in a div with fixed dimensions both horizontally and vertically. I also want the text to have a semi-transparent black background and be able to stretch across two lines if needed.
The issue I'm facing is that the text isn't aligning vertically in the center, and the black background behaves oddly when the text wraps onto a new line.
Here's the current code I'm using:
HTML
<div class="description">
<span>Welcome to the world of beautiful design, technology and music.</span>
</div>
CSS
div.description {
width: 645px;
height: 200px;
margin: 0 auto;
text-align: center;
}
div.description span {
background: rgba(0, 0, 0, 0.5);
color: #FFFFFF;
font-size: 28px;
line-height: 60px;
padding: 10px;
}
I'd like to achieve a similar look to this example without relying on any complex JavaScript tricks to force it into two lines.
Thanks, Charlie