zoukankan      html  css  js  c++  java
  • 如何让未知尺寸的图片、单行文本、多行文本水平垂直居中?

    先看下效果图:

    QQ截图20141203221017

    下面是CSS代码:

    <style type="text/css">
            /*让未知尺寸的图片、单行文本、多行文本水平垂直居中*/
            .wrap {
                border: 1px solid #0094ff;
                 200px;
                height: 200px;
                /*下面是实现垂直居中的关键,没有之一*/
                display: table-cell;
                text-align: center;
                vertical-align: middle;
            }
    
                .wrap .subwrap .content img {
                    /*清除图片下方出现几像素的空白间隙*/
                    vertical-align: middle;
                }
    
                .wrap .subwrap .single {
                    /*让单行文本在容器内垂直居中,只需设置文本的行高等于容器的高度即可*/
                    line-height: 200px;
                }
    
            /*IE 7 以下浏览器*/
            .wrap {
                *display: block;
                *position: relative;
                *float:left;
            }
    
                .wrap .subwrap {
                    *position: absolute;
                    *top: 50%;
                    *left: 50%;
                }
    
                    .wrap .subwrap .content {
                        *position: relative;
                        *top: -50%;
                        *left: -50%;
                    }
        </style>

     

    下面是HTML代码:

    <h3>实现未知尺寸的图片、单行文本、多行文本水平垂直居中</h3>
        <div class="wrap">
            <div class="subwrap ">
                <div class="content ">
                    <img src="http://static.cnblogs.com/images/logo_small.gif" />
                </div>
            </div>
        </div>
        <div class="wrap">
            <div class="subwrap ">
                <div class="content single">
                    单行文本
                </div>
            </div>
        </div>
        <div class="wrap">
            <div class="subwrap ">
                <div class="content ">
                    多行文字垂直居中多行文字垂直居中多行文字垂直居中多行文字垂直居中多行文字垂直居中
                </div>
            </div>
        </div>

    下面是完整的代码:

    <!doctype html>
    <html>
    <head>
        <meta charset="utf-8">
        <title>让未知尺寸的图片、单行文本、多行文本水平垂直居中</title>
        <style type="text/css">
            /*让未知尺寸的图片、单行文本、多行文本水平垂直居中*/
            .wrap {
                border: 1px solid #0094ff;
                width: 200px;
                height: 200px;
                /*下面是实现垂直居中的关键,没有之一*/
                display: table-cell;
                text-align: center;
                vertical-align: middle;
            }
    
                .wrap .subwrap .content img {
                    /*清除图片下方出现几像素的空白间隙*/
                    vertical-align: middle;
                }
    
                .wrap .subwrap .single {
                    /*让单行文本在容器内垂直居中,只需设置文本的行高等于容器的高度即可*/
                    line-height: 200px;
                }
    
            /*IE 7 以下浏览器*/
            .wrap {
                *display: block;
                *position: relative;
                *float:left;
            }
    
                .wrap .subwrap {
                    *position: absolute;
                    *top: 50%;
                    *left: 50%;
                }
    
                    .wrap .subwrap .content {
                        *position: relative;
                        *top: -50%;
                        *left: -50%;
                    }
        </style>
    </head>
    
    <body>
        <h3>实现未知尺寸的图片、单行文本、多行文本水平垂直居中</h3>
        <div class="wrap">
            <div class="subwrap ">
                <div class="content ">
                    <img src="http://static.cnblogs.com/images/logo_small.gif" />
                </div>
            </div>
        </div>
        <div class="wrap">
            <div class="subwrap ">
                <div class="content single">
                    单行文本
                </div>
            </div>
        </div>
        <div class="wrap">
            <div class="subwrap ">
                <div class="content ">
                    多行文字垂直居中多行文字垂直居中多行文字垂直居中多行文字垂直居中多行文字垂直居中
                </div>
            </div>
        </div>
    </body>
    </html>
  • 相关阅读:
    Oracle中的函数——Row_Number()
    Oracle中的函数——Concat()
    EM13C添加agent记录两个报错
    优化SQL集一
    只能在工作时间内更新某表
    WARNING OGG-01519
    plsql developer连接oracle 12.2报错 ora-28040 No matching authentication protocol
    Oracle 12.2 报错:ORA-12012: error on auto execute of job "SYS"."ORA$AT_OS_OPT_SY_7458"
    ORA-04021: timeout occurred while waiting to lock object
    记一次 oracle 12.2 RAC : Transaction recovery: lock conflict caught and ignored
  • 原文地址:https://www.cnblogs.com/vin-c/p/4141542.html
Copyright © 2011-2022 走看看