Vertical center of DIV in HTML

Source: Internet
Author: User

Reference: http://bbs.blueidea.com/viewthread.php? Tid = 1906314

 

Simple Method:

Delete:
<! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

Then:

<HTML xmlns = "http://www.w3.org/1999/xhtml">
<Body>
<Div style = "Background: Blue; position: absolute; left: expression (body. clientWidth-50)/2); top: expression (body. clientHeight-50)/2); width: 50; Height: 50 "> </div>

 

Complex methods:

<! Doctype HTML public " -// W3C // dtd xhtml 1.0 transitional // en "   " Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd " >
< HTML xmlns = " Http://www.w3.org/1999/xhtml " >
< Head >
< Meta HTTP - Equiv = " Content-Type " Content = " Text/html; charset = gb2312 "   />
< Title > ::::::::: 16ue.cn ::::::::: </ Title >
< Style >
Body {padding: 0 ; Margin: 0 ;}
Body, HTML {height: 100 % ;}
# Outer {height: 100 % ; Overflow: hidden; position: relative; width: 100 % ; Background: ivory ;}
# Outer [ID] {display: Table; position: Static ;}
# Middle {position: absolute; top: 50 % ;} /* For explorer only */
# Middle [ID] {display: Table - Cell; vertical - Align: middle; position: Static ;}
# Inner {position: relative; top: - 50 % ; Width: 400px; margin: 0 Auto ;} /* For explorer only */
Div. greenborder {border: 1px solid green; Background - Color: ivory ;}
</ Style >
</ Head >
< Body >
< Div ID = " Outer " >
< Div ID = " Middle " >
< Div ID = " Inner "   Class = " Greenborder " > Vertical center at unknown height
</ Div >
</ Div >
</ Div >
</ Body >
</ Html >

 

Expression is resource-consuming. For example:

<Input value = "0" style = "AF: expression (value ++);">

 

 

 

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.