子父div宽高不定,子div居中
.parent{
position:relative;
}
.child{
position:absolute;
top:50%;
left:50%;
transform:translateX(-50%) translateY(-50%);
}
.parent{
display:flex;
justify-content:center;
align-items:center;
}
.child{
flex:none;
}
.parent{
display:-webkit-box;
-webkit-box-pack:center;
-webkit-box-align:center;
}
父div宽度不定,子宽度固定div居中
.child{
margin:0 auto;
}
父div宽高不定,子宽高固定
.parent{
position:relative;
}
.child{
position:absolute;
top:0;
right:0;
bottom:0;
left:0;
widht:200px;
height:200px;
margin:auto;
}