[css] 寫出div在不固定高度的情況下水平垂直居中的方法?
我知道的有兩種方法
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<style>
* {
padding: 0;
margin: 0;
}
/* flex居中 */
.tith1 {
display: flex;
justify-content: center;
align-items: center;
background: red;
}
/* table居中 */
.tith2 {
text-align: center;
width: 100%;
display: table;
background: blue;
}
.tith2 > span {
display: table-cell;
vertical-align: middle;
}
</style>
<body>
<p class="tith1">
<span>123</span>
</p>
<p class="tith2">
<span>123</span>
</p>
</body>
</html>
個人簡介
我是歌謠,歡迎和大家一起交流前后端知識,放棄很容易,
但堅持一定很酷,歡迎大家一起討論
主目錄
與歌謠一起通關前端面試題
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/262065.html
標籤:其他
