This article collects three CSS tutorial div picture Vertical Center Code Oh, he can vertically center the Div and also center the picture vertically Oh, okay, let's take a look at this vertically centered instance code.
cssbox{ /* Non IE kernel browser recognition Vertical Center * * Display:table-cell; Vertical-align:middle; /* IE kernel browser recognition Vertical Center * * *display:block; * * About the height of 0.873,200*0.873 about 175 * * *font-size:175px; Text-align:center; width:200px; height:200px; } . Cssbox img{ Vertical-align:middle; } Method Two
<!doctype HTML PUBLIC "-//W3C//DTD XHTML 1.0 strict//en" "Http://www.w3.org/tr/xhtml1/dtd/xhtml1-strict.dtd" > <html xmlns= "http://www.zhutiai.com/1999/xhtml" > <head> <meta http-equiv= "Content-type" content= "HTML; charset=gb2312 "/> <title>div+css Picture Vertical Center </title> <style type= "Text/css" > *{margin:0 padding:0; . imgbox{width:400px; height:400px margin:30px; border:1px solid #ddd; text-align:center; line-height:400px; . Imgbox img{Vertical-align:middle; *html. imgbox{font-size:360px; font-family:arial;} </style> </head> <body> <div class= "Imgbox" > <img src= "/article/uploadfiles/200907/20090717185022273.gif"/> </div> </body> </html> 1. The vertical center effect implemented by this method must be in strict mode (DTD XHTML 1.0 Strict) to take effect.
2. For standard browsers (FF,OPERA,CHROME,IE8 ...) Imgbox img{Vertical-align:middle; You can realize that the picture is centered vertically.
3. For IE7, we can use line-height:400px to achieve the goal.
4. The remaining IE6 are *html. imgbox{font-size:360px; font-family:arial; To achieve. One of the 360=400*90%, 400 is the height of the container, 90% is because it is easy to remember, its exact value is 0.873. As to how this numerical value has not been specifically studied ...
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.