CSS: Center Images Using Display:Block and Margin

Centering images can add a special design appeal to your ebook formatting. This can be applied book-wide (to all images) or applied individually. The easiest way to center images is to make the image a block of its own and set the margins to ‘auto’.

Here is an example:

CSS

img.individual {
    display: block;
    margin-left: auto;
    margin-right: auto;
}

HTML

<IMG class="individual" src="..." alt="...">

Castle Rock, John Day Area, Oregon
Castle Rock, John Day Area, Oregon

CSS for all images to be centered

img {
    display: block;
    margin-left: auto;
    margin-right: auto;
}

HTML

<IMG src="..." alt="...">

Leave a Reply

Close Menu

Welcome to Summer: COUPON DISCOUNTS: SAVE10: Save $10 off $50 or more •• SAVE20 Save $20 off $100 or more Dismiss

×
×

Cart