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 关注
- 1773 浏览
相关问题推荐
添加回答
举报