前端佈局總結--居中

居中

  • 水平居中

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;
相關文章
相關標籤/搜索