CSS Vertical Centering

Source: Internet
Author: User

<! 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" &GT;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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.