前端布局总结--居中

居中

  • 水平居中

text-align和inline-blockflex

.parent{
	text-align:center;
}
.child{
	display:inline-block;
}

肯定width的值,设置margin:0 autocode

width:100px;
margin:0 auto;
  • 垂直居中

设置相同的height和line-height(针对行内元素的文字)orm

height:100px;
line-height:100px;
  • 水平垂直居中

绝对定位it

1.已知宽高io

position:absolute;
width:100px;
height:100px;
margin-left:-50px;
margin-top:-50px;

2.未知宽高form

position:absolute;
transform:translate(-50%,-50%);

flextransform

display:flex;
justify-content:center;
align-items:center;
相关文章
相关标签/搜索