zoukankan      html  css  js  c++  java
  • css 实现垂直水平居中

    <html>
    
    <head>
        <meta name="viewport" content="width=device-width, minimum-scale=0.1">
        <title>垂直水平居中</title>
    </head>
    <style>
    /*1 绝对定位+margin */
    #container1 {
    }
    #center1 {
        position:absolute;
        left: 0;
        right: 0;
        top: 0;
        bottom: 0;
        margin:auto;
    }
    /*2 flex 需要设置父容器高度*/
    #container2 {
       height: 800px;
       display: flex;
       justify-content: center;
       align-items: center;
    }
    /*3 table-cell  需要设置父容器宽高*/
    #container3{
        width: 1000px;
        height: 800px;
        display:table-cell;
        text-align:center;
        vertical-align:middle;
    }
    
    /*4 transform  */
    #container4{
        position: relative;
    }
    #center4{
        position: absolute;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
    }
    
    h1{
        color: #fff;
    }
    </style>
    <body   style="margin: 0px; background: #0e0e0e;">
    <h1>推荐 绝对定位+margin  和   transform</h1>
    <div id="container2">
        <img id="center2" style="-webkit-user-select: none;" src="http://picttypec.jnby.com/20180930-jifen-JNBY1.jpg">
    </div>
        
    </body>
    
    </html>
  • 相关阅读:
    mysql新建用户的方法
    工具网站
    如何做好站内锚文本?
    js 创建对象与继承
    js tips
    js作用域链 js没有块级作用域
    css
    instanceof
    问题
    传递,引用副本传递
  • 原文地址:https://www.cnblogs.com/zoumin123/p/10475751.html
Copyright © 2011-2022 走看看