Home > Web Front-end > HTML Tutorial > Example code that can (compatible with IE6+) center images and text horizontally and vertically

Example code that can (compatible with IE6+) center images and text horizontally and vertically

高洛峰
Release: 2017-03-15 09:22:42
Original
1337 people have browsed it

Horizontal and vertical centeringPictures and text (compatible with IE6+) examples

Look directly at the code:

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>水平垂直居中</title>
    <meta name="description" content="">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <style>
        * { margin: 0; padding: 0; font-size: 12px; color: #FFF; }
        .container {
            display: table; /*主要代码*/
            *position: relative;  /*for ie67*/
            background-color: #FF5E53; width: 800px; height: 200px; overflow: hidden; margin: 0 auto;
        }
        .content {
            vertical-align: middle; display: table-cell; text-align: center; /*主要代码*/
            *position: absolute; *top: 50%; *left: 50%; /*for ie67*/
        }
        .center {
            display: inline-block; /*主要代码*/
            *display: inline; zoom: 1; *position: relative; *top: -50%; *left: -50%; /*for ie67*/
            padding: 10px; border: 1px solid #fff;
        }
    </style>
</head>
<body>
<div class="container">
    <div class="content">
        <div class="center">
            <img src="https://static.cnblogs.com/images/adminlogo.gif" /><br/>
            居中居中居中居中居中居中居中居中居中.....
        </div>
    </div>
</div>
</body>
</html>
Copy after login


The above is the detailed content of Example code that can (compatible with IE6+) center images and text horizontally and vertically. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template