Here is an example:
p, span, div,img {
text-align: center;
}
<p>Para</p>
<span>Span</span>
<div>Div</div>
<img src="https://www.google.com/images/nav_logo195.png" />
<div><img src="https://www.google.com/images/nav_logo195.png" /></div>
I found apply text-align: center on img directly doesn't work.
Does this mean it has to be wrapped in an empty div when a centered image is needed?
Is there a better way to do this?
text-align: centercenters horizontally inline content of the container it is applied to. So yes, to center image (inline layout) inside container (block layout), you should apply this css to container, not image.