前端布局总结--居中

痞子三分冷 提交于 2020-10-30 20:01:52

居中

  • 水平居中

text-align和inline-block

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

确定width的值,设置margin:0 auto

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

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

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

绝对定位

1.已知宽高

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

2.未知宽高

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

flex

display:flex;
justify-content:center;
align-items:center;
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!