CSS to solve the vertical center of the picture method

Source: Internet
Author: User
The vertical center of the picture is often encountered in the DIV+CSS layout, the following question we study and give a solution!

The goal is to use a pure CSS to implement an unknown size picture (but width is less than 200px) centered horizontally and vertically in a 200px square container.

The difficulty is two points:

1. vertically centered;
2. The picture is a permutation element with some special characteristics.
As for how to solve, here is a trade-off between the relative structure of clean, CSS simple workaround:

. box {
/* Non-IE's mainstream browser recognized vertical Center method * *
Display:table-cell;
Vertical-align:middle;

/* Set Horizontal Center *
Text-align:center;

/* for IE hack * *
*display:block;
*font-size:175px;/* about the height of the 0.873,200*0.873 about 175*/
*font-family:arial;/* prevent hack failure caused by utf-8, such as GBK code

width:200px;
height:200px;
border:1px solid #eee;
}
. box img {
/* Set Picture Vertical Center * *
Vertical-align:middle;
}

<div class= "box" >

</div>

Of course there are other solutions, do not delve into this, more information please visit Arisisi www.alixixi.com web page Production Tutorial Network _web development Home



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.