<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>定宽块状元素水平居中</title>
<style>
div{
width:600px;
height:300px;
border:1px solid red;
margin:20px;
}
.txtCenter{
text-align:center;
}
.imgCenter{
text-align:center;
display:table-cell;
vertical-align:middle;
}
</style>
</head>
<body>
<div class="txtCenter">我想要在父容器中水平居中显示。</div>
<!--下面是任务部分-->
<div class="imgCenter"><img src="http://img1.sycdn.imooc.com/52da54ed0001ecfa04120172.jpg" /></div>
</body>
</html>
网友评论