さて、この質問は何度も尋ねられ、答えられましたが、それでも私は実用的な解決策を生み出すことができません。
DIVの中央の任意の要素に垂直に配置したいと思います。したがって、上記の質問のリンク先チュートリアルは次のように述べています。
Specify the parent container as position:relative or position:absolute. Specify a fixed height on the child container. Set position:absolute and top:50% on the child container to move the top down to the middle of the parent. Set margin-top:-yy where yy is half the height of the child container to offset the item up.
コードでのこの例:
<style type="text/css">
#myoutercontainer { position:relative }
#myinnercontainer { position:absolute; top:50%; height:10em; margin-top:-5em }
</style>
...
<div id="myoutercontainer">
<div id="myinnercontainer">
<p>Hey look! I'm vertically centered!</p>
<p>How sweet is this?!</p>
</div>
</div>
チュートリアルのスクリーンショットが示すものとは反対に、これは機能しません。私が変更した唯一のことは、外側のDIVの周りに境界線を追加することでした。これにより、垂直方向の配置を確認できます。
これは、直線のようにレンダリングされる高さゼロのDIVを生成するだけです。外側のDIVに高さを追加すると、内側のコンテンツを表示できますが、実際にはコンテンツが垂直方向に整列しません。では、なぜこの例が機能しないのでしょうか。