上下左右居中解決方法

水平居中

  1. display: inline/inline-block;

text-align: center;設置

  1. display: block;

margin-leftmargin-right均設置爲auto

垂直居中

1. Position absolute

{
	position: absolute;
	top: 50%;
	left: 50%;
	transform: translateX(-50%) translateY(-50%)
}

2. Display table

將父元素設置display: table;
再將元素設置display: table-cell;

{
	display: table-cell;
	vertical-align: middle;
	text-align: center;
}

3. Flex

{
	display: flex;
	justify-content: center;
	align-items: center;
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章