Is it possible to horizontally center align some text if it fits in a single line, but do not do center align and do white-space: normal if it takes up multiple lines (preferrably, but not necessarily, without javascript)?
Is it possible to horizontally center align some text if it fits in a
Share
Here is an HTML+CSS solution.
The tricks are:
The
<span>inside<p>has thedisplay: inline-box;property so it will shrink to the size of its content.The
<p>hastext-align: centerso the<span>will be centred if the size of the<span>is less than the width of the<p>.The
<span>hastext-align: leftso the text will actually be left-aligned.