zoukankan      html  css  js  c++  java
  • css元素垂直居中

    一、css元素垂直居中初始状态

    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="UTF-8">
    <title>css元素垂直居中</title>
    <style type="text/css">
    .wrapper{
    background-color: #f24444;
    200px;
    height:200px;
    margin:0px auto;

    text-align:center;
    }
    /* .content{
    line-height:200px;
    }*/
    </style>
    </head>
    <body>
    <div class="wrapper">
    <div class="content">世上无难事,只怕有心人。</div>
    </div>
    </body>

    </html>

    二、1、line-height文本垂直居中

    .content{
    line-height:200px;
    }

    2、line-height图片垂直居中

    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="UTF-8">
    <title>css元素垂直居中</title>
    <style type="text/css">
    .wrapper{
    background-color: #f24444;
    200px;
    height:200px;
    margin:0px auto;
    text-align:center;
    }
    .content{
    line-height:200px;
    }
    .content img{
    vertical-align: middle;

    }
    </style>
    </head>
    <body>
    <div class="wrapper">
    <div class="content"><img src="s2.png"></div>
    </div>
    </body>

    </html>

    
    
    
    
    三、table方法垂直居中
    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="UTF-8">
    <title>css元素垂直居中</title>
    <style type="text/css">
    .wrapper{
    background-color: #f24444;
    200px;
    height:200px;
    margin:0px auto;
    text-align:center;
    display:table;
    }
    .content{
    display:table-cell;
    vertical-align:middle;
    }

    </style>
    </head>
    <body>
    <div class="wrapper">
    <div class="content">世上无难事,只怕有心人</div>
    </div>
    </body>

    </html>

    四、1、绝对定位与负位移垂直居中
    .wrapper{
    background-color: #f24444;
    200px;
    height:200px;
    margin:0px auto;
    text-align:center;
    position:relative;
    }
    .content{
    position:absolute;
    top:50%;
    left:50%;
    height:30%;
    50%;
    margin:-15% 0 0 -25%;
    }

    五、绝对定位与margin扩展

    .wrapper{
    background-color: #f24444;
    200px;
    height:200px;
    margin:0px auto;
    text-align:center;
    position:relative;
    }
    .content{
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    right: 0;
    50%;
    height: 30%;
    margin: auto;
    }

    六、padding垂直居中
    .wrapper{
    background-color: #f24444;
    margin:0px auto;
    text-align:center;
    padding:5% 0;
    }
    .content{
    padding:10% 0;
    }

    
    
    七、浮动方法垂直居中

    .wrapper{
    background-color: #f24444;
    text-align:center;
    height:250px;
    }
    .floater{
    float:left;
    height:50%;
    100%;
    margin-bottom:-50px;
    }
    .content{
    clear:both;
    height:100px;
    }

    
    
  • 相关阅读:
    verilog 数组参数
    跨时钟域设计【一】——Slow to fast clock domain
    跨时钟域设计【二】——Fast to slow clock domain
    跨时钟域设计【三】—— 数据同步
    Vivado学习笔记_002
    使用modelsim仿真DDR3时编译出错的解决方法
    Modelsim仿真tcl脚本与wave.do文件
    %s 与 %0s在 verilog中的区别
    BFM1
    verilog 常用系统函数及例子
  • 原文地址:https://www.cnblogs.com/wuliwuli/p/5170820.html
Copyright © 2011-2022 走看看