Centering vertically

maplejar
20 Jun 2016, 12:14
I know that:

PrintCentered ("Game Title<br/><br/>by<br/><br/>J. Brian Terry<br/><br/>(Press any key to continue....)")


will center that block of text horizontally. How can I get it to also center vertically?

Thanks!

jaynabonne
20 Jun 2016, 15:20
If you can live with it being "sort of centered", you can output a few <br>s to move it down the page a little. It won't be perfectly centered, but it might be good enough.

If you want it to be exactly centered, no matter what their window size, then you'll need some sort of absolutely positioned HTML element. To have it be sizeable to the window with styles alone (in my experience), you need to change the styles on the html and body element to have a position, so that your element can be positioned correctly to the window (otherwise, the body will be smaller than the window size). The alternative is to use JavaScript to get the bounds and positions for the various elements and then position the element yourself.

(recap)
The main problem is that the area the output is going into is auto-sized. So in the beginning, it is only as large as any text that is in it. As such, it has no vertical height beyond what your text takes up. So it is effectively centered vertically at that point, relative to the output element (which is smaller than the window). To work around that, you need to step outside that element using an absolutely positioned element and then size it relative to the window instead of the html body.

(Would "sort of centered" be good enough? :) )

maplejar
21 Jun 2016, 07:05
Well - I have decided that "sort of centered" would indeed be good enough. :) Thank you!