水平垂直居中图片及文字(兼容IE6+)实例

直接看代码:

复制代码
<!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>
复制代码

 

posted @   键盘敲飞  阅读(318)  评论(0编辑  收藏  举报
编辑推荐:
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
阅读排行:
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!
点击右上角即可分享
微信分享提示