Fandom

Wikianswers

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,031,871questions on
Wikianswers
Add New Page
Talk0 Share

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.

You can use "text-align:center;" for the parent div. For example:

div.box { 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