zoukankan      html  css  js  c++  java
  • 【页面架构】水平居中+垂直居中

    实现一:

    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="utf-8"/>
    <title>居中</title>
    <link rel="stylesheet" type="text/css" href="demo.css">
    <style type="text/css">
        body{margin:20px;}
        .parent{width:200px;height:300px;}
        
        .parent{
            text-align: center;
            display: table-cell;
            vertical-align: middle;
        }
        .child{
            display: inline-block;
        }
    </style>
    </head>
    <body>
    <div class="parent">
        <div class="child">DEMO</div>
    </div>
    </body>
    </html>

    实现二:

    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="utf-8"/>
    <title>居中</title>
    <link rel="stylesheet" type="text/css" href="demo.css">
    <style type="text/css">
        body{margin:20px;}
        .parent{width:200px;height:300px;}
        
        .parent{
            position: relative;
        }
        .child{
            position: absolute;
            left: 50%;
            top: 50%;
            transform: translate(-50%,-50%);
        }
    </style>
    </head>
    <body>
    <div class="parent">
        <div class="child">DEMO</div>
    </div>
    </body>
    </html>

    实现三:

    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="utf-8"/>
    <title>居中</title>
    <link rel="stylesheet" type="text/css" href="demo.css">
    <style type="text/css">
        body{margin:20px;}
        .parent{width:200px;height:300px;}
        
        .parent{
            display: flex;
            justify-content: center;
            align-items: center;
        }
    </style>
    </head>
    <body>
    <div class="parent">
        <div class="child">DEMO</div>
    </div>
    </body>
    </html>

    附录:demoe.css

    html,body,h1,h2,h3,h4,h5,h6,div,dl,dt,dd,ul,ol,li,p,blockquote,pre,hr,figure,table,caption,th,td,form,fieldset,legend,input,button,textarea,menu{margin:0;padding:0;}
    header,footer,section,article,aside,nav,hgroup,address,figure,figcaption,menu,details{display:block;}
    table{border-collapse:collapse;border-spacing:0;}
    caption,th{text-align:left;font-weight:normal;}
    html,body,fieldset,img,iframe,abbr{border:0;}
    i,cite,em,var,address,dfn{font-style:normal;}
    [hidefocus],summary{outline:0;}
    li{list-style:none;}
    h1,h2,h3,h4,h5,h6,small{font-size:100%;}
    sup,sub{font-size:83%;}
    pre,code,kbd,samp{font-family:inherit;}
    q:before,q:after{content:none;}
    textarea{overflow:auto;resize:none;}
    label,summary{cursor:default;}
    a,button{cursor:pointer;}
    h1,h2,h3,h4,h5,h6,em,strong,b{font-weight:normal;}
    del,ins,u,s,a,a:hover{text-decoration:none;}
    body,textarea,input,button,select,keygen,legend{font:30px/1.5 'microsoft yahei';color:#333;outline:0;}
    body{background:#fff;}
    a,a:hover{color:#333;}
    .parent{background:#ddd;}
    .child{background:#666;color:#fff;}
  • 相关阅读:
    Tarjan算法求双连通分量
    Tarjan
    前端技术实现js图片水印
    记录一下ionic canvas图片,还有canvas里面的图片跨域的问题
    ionic cordova screenshot 使用和操作
    关于ionic2 更新到ionic3 后组件不能用的解决方案
    背景图处理,这是个好东西记录一下
    radio样式的写法,单选和多选如何快速的改变默认样式,纯CSS,
    ionic使用cordova插件中的Screenshot截图分享功能
    ionic中执行pop返回上一个页面,还需要执行操作
  • 原文地址:https://www.cnblogs.com/zachary93/p/6084277.html
Copyright © 2011-2022 走看看