I want to use media queries to centre this logo when viewed in phone / tablet sized viewports.

How would I do this? I have a workaround at the moment which is swaps out the img.logo for a roughly centred div (not quite right), it's certainly not ideal.

Any help would be much appreciated on best practice.

chris_upjohn
—
2012-12-20T12:10:22Z —
#2

See the following pen for a demo, since you know the width of the image you can simply use a left offset then pull it back with a margin which will work in any browser.

DaveMaxwell
—
2012-12-20T13:08:27Z —
#3

An alternative would be to just set the img.logo to display as block (images display inline as default) and use the auto margins. This allows you to use different size logos depending on your display, and you don't need to worry about the image size.

img.logo { display:block; margin: 10px auto; border: none; }

ralphm
—
2012-12-20T13:11:44Z —
#4

Yes, and if that image is in a block level container like a div, you could also set the div to width: 100% and text-align: center, which should also center the image.

SO many options.

Zapppa
—
2012-12-20T15:11:18Z —
#5

DaveMaxwell said:

An alternative would be to just set the img.logo to display as block (images display inline as default) and use the auto margins. This allows you to use different size logos depending on your display, and you don't need to worry about the image size.

img.logo { display:block; margin: 10px auto; border: none; }

of course! thanks

I had it set to float left in my large viewport window. Sorted now! :lol::D