1. 程式人生 > >子級盒子在父級盒子中水平垂直居中

子級盒子在父級盒子中水平垂直居中

方法一

子盒子

position:absolute;

margin:auto;

top:0;

right:0;

bottom:0;

left:0;

方法二

設定父級盒子

display:table-cell; //實現左側浮動,右側自適應 但應改回產生影響對後面的塊級元素?

vertical-align:middle;

text-align: center;

設定子級盒子:

display:inline-block;

方法三

設定父集盒子display:flex;

justify-content:center;

align-items:center;

設定子級盒子

方法四

設定父級盒子position:relative;

設定子級盒子:position:absolute;left:50%;top:50%;margin-left: -50px;margin-top:-50px;