5 回答

TA貢獻4條經驗 獲得超2個贊
<!DOCTYPE HTML>
<html>
? ? <head>
? ? ? ? <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
? ? <title>Html和CSS的關系</title>
? ? <style type="text/css">
? ? .father{
? ? ? ? width:600px;
? ? ? ? height:600px;
? ? ? ? background:red;
? ? ? ? display:table-cell;
? ? ? ? vertical-align:middle;
? ? }
? ??
? ? .son{
? ? ? ? text-align:center;
? ? ? ? height:100px;
? ? ? ? background:blue;
? ? ? ??
? ? }
? ??
? ? </style>
? ??
? ? </head>
? ? <div class="father"><!--這個是父元素-->
? ? <div class="son"><!--這個是子元素-->
? ??
? ? ? ? <h1 class="title">hello word</h1>
? ? ? ? <div class="content">這里面是一堆元素</div>
? ? ?
? ? </div>
</div>
</html>
紅色為父元素,藍色為子元素,藍色必須設置了定高才能垂直居中,不知道是不是你想要的效果。

TA貢獻19條經驗 獲得超5個贊
.parent{ ????line-height:600px; ????text-align:center; ?} .child{ ????display:inline-block; ????text-align:left; ????line-height:normal; ????vertical-align:middle; ?}
還有一種方式是絕對定位,用margin-left,margin-top負值調整。
也可以用justify-content:center;
??????????????? align-items:center
- 5 回答
- 0 關注
- 1839 瀏覽
相關問題推薦
添加回答
舉報