12
margin:autoを使用してdivを垂直方向に揃える
したがって、を使用すると、divを水平方向に中央揃えできることがわかりますmargin:0 auto;。必要がありmargin:auto auto;、私はそれが動作するはずだと思うどのように動作しますか?垂直方向にも中央揃えですか? なぜうまくいかないのvertical-align:middle;ですか? .black { position:absolute; top:0; bottom:0; left:0; right:0; background:rgba(0,0,0,.5); } .message { background:yellow; width:200px; margin:auto auto; padding:10px; } <div class="black"> <div class="message"> This is a popup message. </div> </div> コードスニペットを実行する結果を非表示スニペットを展開 JSFiddle