Skip to content

Instantly share code, notes, and snippets.

@libo1106
Created August 8, 2013 10:19
Show Gist options
  • Save libo1106/6183485 to your computer and use it in GitHub Desktop.
Save libo1106/6183485 to your computer and use it in GitHub Desktop.
未知高度垂直居中
<!--
高版本浏览器可以直接使用table-cell配合vertical-align来实现垂直居中。
IE6\7则需要多一个容器,调整定位来实现
-->
<style>
.wrap{
width:500px;height:300px;border:3px solid #ddd;margin:0 auto;padding:20px;display:table;
*position:relative;
}
.hack{
display:table-cell;vertical-align:middle;
*position:absolute;*top:50%;
}
.cnt{
*position:relative;*top:-50%;
}
</style>
<div class="wrpa">
<div class="hack">
<div class="content">
未知高度的东东
</div>
</div>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment