Home > Web Front-end > HTML Tutorial > The image of uncertain size is vertically centered_html/css_WEB-ITnose

The image of uncertain size is vertically centered_html/css_WEB-ITnose

WBOY
Release: 2016-06-24 11:51:24
Original
1410 people have browsed it

If the image size is uncertain, how to center the image vertically and horizontally in the DIV? Of course, if you use a form, it's a different story. Here we only discuss the use of css for control.

If you only want to center it horizontally, use the text-align:center; (margin:0 auto; in Firefox) attribute. However, vertical centering seems difficult to achieve. Whether using "vertical-align:middle;" in CSS or using img's align="absmiddle", the image seems to be indifferent in the vertical direction.

I found the following method and made a collection.

Style part:


.middle-out{

width: 600px;

height: 385px;

position: relative;

display: table-cell;

vertical-align: middle;

text-align:center;

border: 1px solid #f00;

}

.middle-in{

position: static;

*position:absolute;

top:50%;

}

.middle-out .middle-in img{

position:static;

*position: relative;

top:-50%;

left:-50%;

}

HTML part:

< div class="middle-out">

source:php.cn
Previous article:How to accurately place the input box in the image of the login page? _html/css_WEB-ITnose Next article:Website front-end static page html template_html/css_WEB-ITnose
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Latest Issues
Related Topics
More>
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template