In addition to special instructions on vertical and horizontal center of images of unknown size in a known container, this site uses the creation of shared authorization signatures and non-commercial purposes. Please respect the labor results.
In the CSS layout, vertical center of images of unknown sizes has always been a headache. The standard browser only needs to set the line-height of the container and the vertical-align: middle; of the image, but it is useless to IE. I saw a solution to IE on a foreign website a few months ago. I don't feel very ideal and I didn't take it seriously. Recently, I have seen some friends asking similar questions, turning out the code and changing the code for IE.
CSS
. Box {
Height: 140px;
Width: 200px;
Border: solid 1px #666;
Text-align: center;/* horizontal center */
Line-height: 140px;
Font-size: 126px;/* center IE vertically */
}
. Box [class] {
Font-size: 12px;/* this value is required by the standard browser */
}
Img {
Vertical-align: middle;/* vertical center of standard browser images */
}
The font-size of the original foreigner code is the same as the height. After the test, the height of the container is higher than that of the standard browser, and the font size is reduced by 10 percent of the height of the container multiple times, in this way, it looks similar. The reason is unclear.
The test is successful in IE5.5, IE6.0, FF1.5, and Opera9.0, and is invalid for IE5.0 and IE7.0.