<! DOCTYPE html>
<meta charset= "UTF-8" >
<title>Document</title>
<style type= "Text/css" >
/*===================================*/
. d1{
height:60px;
line-height:60px;
BORDER:1PX solid black;
}
/*===================================*/
. d2{
margin-top:20px;
padding-top:20px;
padding-bottom:20px;
BORDER:1PX solid black;
}
. warp{
margin-top:20px;
display:table;
BORDER:1PX solid yellow;
height:400px;
width:300px;
}
. d3{
Vertical-align:middle;
Display:table-cell;
border:1px solid Green;
}
/*===================================*/
. outer{
margin-top:20px;
display:table;
border:1px solid red;
height:600px;
width:300px;
Overflow:hidden;
*position:relative;
Background-color:green\0; /* IE 8/9*/
background-color:blue\9\0; /* IE 9*/
*background-color: #dddd00; /* IE 7*/
_background-color: #CDCDCD; /* IE 6*/
}
. inner{
Vertical-align:middle;
Display:table-cell;
/*BORDER:1PX Solid black;*/
/*text-align:left;*/
*position:absolute;
*top:50%;
}
. content{
*position:relative;
*top:-50%;
}
/*===================================*/
</style>
<body>
<div class= "D1" >1: I am a single line vertical centering, principle: height:60px = = = line-height:60px </div>
<div class= "D2" >2: Vertical centering of multiple lines of unknown height text, principle: padding-top:20px; = = = Padding-bottom:20px;</div>
<div class= "Warp" >
<div class= "D3" >
3, the center of the multi-line text fixed height, principle,:
Parent element style: display:table;height:400px;
child element style: Vertical-align:middle;display:table-cell;
<span style= "font-size:20px;color:red" >
Internet Explorer 6,7 does not correctly understand display:table and Display:table-cell,
Internet Explorer 6,7 and the following versions are not valid
</span>
</div>
</div>
<div class= "outer" >
<div class= "inner" >
<div class= "Content" >
<span style= "font-size:20px;color:red" >
Internet Explorer 6,7 does not correctly understand display:table and Display:table-cell,
Internet Explorer 6,7 and the following versions are not valid <br/>
</span>
Compatible with Internet Explorer 6, 7: Centering the fixed height of multiple lines of text
<br/>
. outer{
margin-top:20px;
display:table;
border:1px solid red;
height:300px;
width:300px;
Overflow:hidden;
*position:relative;
}<br/>
. inner{
Vertical-align:middle;
Display:table-cell;
/*BORDER:1PX Solid black;*/
/*text-align:left;*/
*position:absolute;
*top:50%;
}
</div>
</div>
</div>
<!--below don't know what's going on, not up to the left
<div class= "outer" >
<div class= "inner" >
<div id= "Content" >
Compatible with Internet Explorer 6: Centering multiple lines of text fixed height
</div>
</div>
</div>
-
</body>
CSS is centered vertically