标签:
html file:
<body>
<div class=‘parentelement‘>
<div class=‘childelement‘>
想让子元素在父元素内水平、垂直居中
</div>
</div>
</body>
css file:
.parentelement{
width:200px;
height:200px;
background-color:red;
position:relative;
}
.childelement{
width:50%;
height:50%;
background-color:green;
position:absolute;
top:50%;
left:50%;
-webkit-transform: translate(-50%,-50%);
-moz-transform: translate(-50%,-50%);
-o-transform: translate(-50%,-50%);
transform: translate(-50%,-50%);
}
标签:
原文地址:http://www.cnblogs.com/jaina/p/5725561.html