zoukankan      html  css  js  c++  java
  • 垂直居中,水平居中html例子

    <!DOCTYPE html>
    <html lang="en">
    <head>
    <title>Vertical Centering with Equal Top and Bottom Padding</title>
    
    <meta charset="utf-8">
    <meta name="description" content="" />
    
    <style type="text/css">
    #parent {
    background: #ccc;
    }
    
     
    
    /* horizontal centering */
    #parent {
    width: 400px;
    margin: 20px auto;
    }
    
    .child {
    text-align: center;
    background: #999;
    color: #fff;
    }
    
    /* vertical centering */
    #parent {
    padding: 5% 0;
    }
    
    .child {
    padding: 1% 0;
    }
    
    body {
    margin: 0px auto; 
    background-color: beige;
    }
    </style>
    
    </head>
    
    <body>
    <form>
    <div id="parent">
    <div class="child">用户&nbsp;<input type="text" /></div>
    <div class="child">密码&nbsp;<input type="text" /></div>
    <div class="child"></div>
    <div class="child" style="background: #ccc;">
    <input type="submit" value="登录" style="80px;" /></div>
    </div>
    </form>
    <script type="text/javascript">
    var p = document.getElementById("parent");
    
    resize_fn = function (e) {
    
    var zbody_height = Math.max(document.documentElement.scrollHeight, document.documentElement.clientHeight);
    var zdiv_height = Math.max(p.scrollHeight, p.clientHeight);
    var ztop = (zbody_height - zdiv_height) / 2;
    
    p.style.marginTop = ztop + "px";
    };
    
    //var w = document.getElementsByClassName("child");
    var w = document.querySelectorAll(".child");
    
    for (var i = 0; i < w.length;i++) {
    
    var oi = w.item(i);
    
    oi.style.background = "#ccc";
    
    
    }
    
    //p.style.background = "beige";
    resize_fn();
    document.body.onresize = resize_fn;
    </script>
    </body>
    </html>

  • 相关阅读:
    100篇论文
    Tengine vs openresty
    Dottrace跟踪代码执行时间
    Linux Server
    Linux+Apache+Mysql+Php
    linux+nginx+mysql+php
    tshark命令行的使用(转)
    tcpdump VS tshark用法(转)
    Lua语言在Wireshark中使用(转)
    doc-remote-debugging.html
  • 原文地址:https://www.cnblogs.com/coolyylu/p/5165387.html
Copyright © 2011-2022 走看看