Skip to content

Instantly share code, notes, and snippets.

@liveme
Created March 21, 2014 06:08
Show Gist options
  • Save liveme/9680501 to your computer and use it in GitHub Desktop.
Save liveme/9680501 to your computer and use it in GitHub Desktop.
未知高度容器垂直居中
/*
*@ Name: 未知高度容器垂直居中
*@ Update: 2013-10-20
*@ Doc&Demo: http://www.liveme.org/about-the-vertical-center.html
*/
.mod-vc {
text-align: center;
font-size: 0;
*word-spacing: -1px; /* IE6、IE7 */
/*height: 100%;*/
/* 继承父级高度 */
}
/* 修复 Safari 5- inline-block 的空隙 */
@media (-webkit-min-device-pixel-ratio:0) {
.mod-vc {
letter-spacing: -5px;
}
}
.mod-vc .inner, .mod-vc:after, .mod-vc i {
display:inline-block;
*display:inline;
*zoom:1;
vertical-align:middle;
}
.mod-vc .inner{
letter-spacing: normal;
word-spacing: normal;
font-size:12px;
width: 100%; /* 保证连续字符也能居中 */
white-space: normal;
word-wrap: break-word;
padding: 0 !important; /* 防止设置边距导致居中失效 */
margin: 0 !important;
}
.mod-vc:after, .mod-vc i {
width:0;
height:100%;
}
.mod-vc:after {
content:'';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment