Using CSS to vertically center a picture within a div

Source: Internet
Author: User

A DIV is known to have an IMG, both of which do not know the height, but the height of the image must be less than the height of the div

The code is as follows:

. box {
/* Vertical Centering method recognized by the mainstream browser of non IE */
Display:table-cell;
Vertical-align:middle;
/* Set Horizontal Center */
Text-align:center;
/* Hack for IE * *
*display:block;
*font-size:175px;/* about a height of 0.873,200*0.873 about 175*/
*font-family:arial;/* prevent non-utf-8 caused by hack failure problems, such as GBK encoding */
width:200px;
height:200px;
border:1px solid #eee;
}
. box img {
/* Set Picture vertically centered */
Vertical-align:middle;
}
<div class= "box" >

</div>

Using CSS to vertically center a picture within a div

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.