Skip to content

Instantly share code, notes, and snippets.

@cycold
Created April 1, 2014 07:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cycold/9909647 to your computer and use it in GitHub Desktop.
Save cycold/9909647 to your computer and use it in GitHub Desktop.
*{margin:0;padding:0;}
.box{
height:200px;
width:300px;
background:pink;
margin:30px auto;
font-size:0;
}
.box:before{
content: '我是那个备胎元素';
display: inline-block;
vertical-align: middle;
width: 0;
height: 100%;
}
.text{
display: inline-block;
font-size:16px;
vertical-align: middle;/* 保证文字垂直居中 */
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>多行文本未知高度垂直居中-by一丝</title>
</head>
<body>
<body>
<div class="box">
<p class="text">
多行文本未知高度垂直居中-by 一丝多行文本未知高度垂直居中-by 一丝多行文本未知高度垂直居中-by 一丝
</p>
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment