zoukankan      html  css  js  c++  java
  • 元素居中的两种方法,transform和margin

    1.transform :translate(-50%,-50%)

    <!DOCTYPE html>
    <html lang="en">
    
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta http-equiv="X-UA-Compatible" content="ie=edge">
        <title>Document</title>
        <style>
            body,
            html {
                width: 100%;
                height: 100%;
                margin: 0;
                padding: 0
            }
            
            .box {
                width: 100%;
                height: 100%;
                background: red
            }
            
            .div1 {
                width: 200px;
                height: 200px;
                background: black;
                position: absolute;
                left: 50%;
                top: 50%;
                transform: translate(-50%, -50%)
            }
        </style>
    </head>
    
    <body>
        <div class="box">
            <div class="div1"></div>
        </div>
    
    </body>
    
    </html>

    2.top,bottom,left,right和margin:auto

    <!DOCTYPE html>
    <html lang="en">
    
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta http-equiv="X-UA-Compatible" content="ie=edge">
        <title>Document</title>
        <style>
            body,
            html {
                width: 100%;
                height: 100%;
                margin: 0;
                padding: 0
            }
            
            .box {
                width: 100%;
                height: 40%;
                background: red;
                position: relative
            }
            
            .div1 {
                width: 200px;
                height: 200px;
                background: black;
                position: absolute;
                left: 0;
                right: 0;
                top: 0;
                bottom: 0;
                margin: auto
            }
        </style>
    </head>
    
    <body>
        <div class="box">
            <div class="div1"></div>
        </div>
    
    </body>
    
    </html>
  • 相关阅读:
    linux三剑客之一:grep详细介绍
    Linux less命令:查看文件内容
    django-crontab执行定时任务
    mahout的数据处理--【根据文本文件创建vector】
    hbase编程demo
    hive0.11安装与配置
    hadoop1.1.2升级1.2.1
    hadoop 1.1.2和 hive 0.10 和hbase-0.94.10-security整合
    hbase配置
    hbase与storm的冲突
  • 原文地址:https://www.cnblogs.com/moxiaowohuwei/p/7644888.html
Copyright © 2011-2022 走看看