View Single Post
Old 12-26-2014, 11:00 AM   #25
dgatwood
Curmudgeon
dgatwood ought to be getting tired of karma fortunes by now.dgatwood ought to be getting tired of karma fortunes by now.dgatwood ought to be getting tired of karma fortunes by now.dgatwood ought to be getting tired of karma fortunes by now.dgatwood ought to be getting tired of karma fortunes by now.dgatwood ought to be getting tired of karma fortunes by now.dgatwood ought to be getting tired of karma fortunes by now.dgatwood ought to be getting tired of karma fortunes by now.dgatwood ought to be getting tired of karma fortunes by now.dgatwood ought to be getting tired of karma fortunes by now.dgatwood ought to be getting tired of karma fortunes by now.
 
dgatwood's Avatar
 
Posts: 629
Karma: 1623086
Join Date: Jan 2012
Device: iPad, iPhone, Nook Simple Touch
Quote:
Originally Posted by RbnJrg View Post
No, I'm afraid not By adding "text-align: center" won't center the image vertically and to center it horizontally by using that property, the image would have to be showed as "inline" element; otherwise "text-align: center" won't work. To center block elements you need "margin-left: auto" and "margin-right: auto".
Ugh. My brain wasn't turned on when I wrote that.

The SVG code I posted does, in fact, center the image, both vertically and horizontally. That's handled by the "mid" in preserveAspectRatio="xMidYMid". The containers are all styled to fill the body size, which in the absence of content that would overflow the bounds, fills the viewport. So by adding the image and telling it to scale to fit, centered, within that container, you're effectively centering within the viewport.

Try it in a browser, and you'll see that it remains centered, regardless of which dimension is larger than the content.

And because it is SVG, if you want to include captions, you can readily do so using SVG text elements, giving you complete control over the page layout, and the resulting text should still be searchable as text in most readers.

Last edited by dgatwood; 12-26-2014 at 11:10 AM.
dgatwood is offline   Reply With Quote