水平方向をセンタリング
ブロック要素の幅が200pxの場合
position: absolute; margin-left:-100px; left: 50%; |
margin-left の値はセンタリングするブロック要素の幅の半分 |
水平・垂直 両方向をセンタリング
ブロック要素の幅が200px、高さが100pxの場合
position: absolute; margin-left:-100px;margin-top:-50%; left: 50%;top: 50%; |
margin-left および margin-top の値はセンタリングするブロック要素の幅および高さの半分 |
※詳しくはこのサイトを参照。