Two methods for vertical center of uncertain height in css

Source: Internet
Author: User

Example 1

Uncertain height vertical center

The code is as follows: Copy code

/* Center <*/
. Vetically {
Vertical-align: middle;
Display: table-cell;
* Position: relative;
}
. Vetically_C {
Display: block;
Margin: 0 auto;
Text-align: center;
* Position: absolute;
* Top: 50%;
* Left: 50%;
* Margin-top: expression (-(this. height)/2 );
* Margin-left: expression (-(this. width)/2 );
}
/* Center> */

Example 2

The standard browser is the same as above. The difference is that for IE6/IE7, an empty label is inserted before the img label.

The code is as follows: Copy code

<Html xmlns = "http://www.w3.org/1999/xhtml">
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312"/>
<Title> method 2-vertical center of images with unknown height </title>
<Style type = "text/css">
Body {
Height: 100%;
}
# Box {
Width: 500px; height: 400px;
Display: table-cell;
Text-align: center;
Vertical-align: middle;
Border: 1px solid # d3d3d3; background: # fff;
}
# Box img {
Border: 1px solid # ccc;
}
</Style>
<! -- [If IE]>
<Style type = "text/css">?
# Box I {
Display: inline-block;
Height: 100%;
Vertical-align: middle
}
# Box img {
Vertical-align: middle
}
</Style>
<! [Endif] -->
</Head>
<Body>
<Div id = "box">
<I> </I>
</Div>
</Body>
</Html>

Related Article

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.