一、 绝对定位+margin: |
给父元素定位: position : relative ; |
给子元素定位: position : absolute ; |
给子元素定位: top : 50% ; left : 50% ; |
给子元素添加: margin-top :-子元素高度的一半; margin-left :-子元素宽度的一半; |
二、 transform: |
给子元素添加:transform:translate( -50% , -50% ); |
三、 flex |
给父元素添加: display :flex;justify- content : center ;align-items: center ; |