这里有三种方法:知道盒子的宽度和高度:div{position:absolute;宽度:500px;高度:500px;保证金:自动;顶部:0;左:0;按钮:0;右:0;}这是一个经典的方法:.parent{position:relative;}.child{width:500px;/*不需要知道宽高*/height:500px;位置:绝对;top:50%;/*相对于父级的50%*/left:50%;/*相对于父级的50%*/transform:translate(-50%,-50%);/*相对于自身50%*/}使用css3flex布局div{display:flex;判断内容:中心;对齐项目:居中;}
