Home > Article > Web Front-end > Examples of horizontal and vertical centering of commonly used images in containers_javascript techniques
This is an example of horizontal and vertical centering of an image of unknown size in a container of known size. Original title: "Centering an image of unknown size in an outer container of known size".
This example of horizontal and vertical centering can work normally in IE5.
IE uses inline-blocks, non-IE uses table-cell and vertical-align.
CSS code:
The following is a reference fragment:
/* for non-IE browsers */
div.holder {width:750px; height:300px; background:# f8f8f8;
border:1px solid #777; text-align:center; display:table-cell; vertical-align:middle;}
}
#container {text -align:center; width:100%; display:inline-block; vertical-align:middle;}