可以使用弹性盒子flex
父盒子使用: display:flex, 子元素使用:margin: atuo
父盒子使用: display:flex,align-items: center; 子元素使用:margin:0 atuo
父元素使用:display: flex; align-items: center; justify-content: center;
定位position
父元素使用: position: relative;子元素使用: position: absolute; left: 0; top: 0; right: 0; bottom: 0; margin: auto;
*兼容性较好,缺点:不支持IE7以下的浏览器
使用position + transform
不定宽高时
父元素使用: position: relative;子元素: position: absolute; left: 50%;top: 50%; transform: translate(-50%,-50%);
有宽高时
父元素使用: position: relative;子元素: width: 100px; height: 100px; position: absolute; left: 50%; top: 50%; margin-left: -50px; margin-top: -50px;

被折叠的 条评论
为什么被折叠?



