Welcome! Enter your question below. Please use words like "Who, What, Where, When, Why, How, etc..." in your question. Nothing to ask? Click here for a random, un-answered question.

How do you always center an image on a web page (like CSS background-position: center center; for background images)?

1,021,832questions on
Add New Page
Add New Page Talk0

You can use "text-align:center;" for the parent div. For example: { width:600px; text-align:center; }

will center the image (and text) inside that div.

Use it like this:

<div class="box"> <img src="some_image.jpg" /> </div>

Easier than setting the padding or margin on the image or the outer div.

To vertically align it though, there's no good solution without javascript.

Also on Fandom

Random Wiki