Skip to content

Instantly share code, notes, and snippets.

@ruyaoyao
Created May 23, 2017 02:20
Show Gist options
  • Save ruyaoyao/fac65ed8492ef2e3ae42e3c95005175a to your computer and use it in GitHub Desktop.
Save ruyaoyao/fac65ed8492ef2e3ae42e3c95005175a to your computer and use it in GitHub Desktop.
多行文本未知高度垂直居中-by一丝 // source http://jsbin.com/xowiyuw
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>多行文本未知高度垂直居中-by一丝</title>
<style id="jsbin-css">
*{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;/* 保证文字垂直居中 */
}
</style>
</head>
<body>
<body>
<div class="box">
<p class="text">
多行文本未知高度垂直居中-by 一丝多行文本未知高度垂直居中-by 一丝多行文本未知高度垂直居中-by 一丝
</p>
</div>
<script id="jsbin-source-css" type="text/css">*{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;/* 保证文字垂直居中 */
}</script>
</body>
</html>
*{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;/* 保证文字垂直居中 */
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment