zoukankan      html  css  js  c++  java
  • 盒子居中的方法

    //html部分
    <div class="main_box">
                <div class="box"></div>
    </div>

    第一种:

    <style type="text/css">
            .main_box {
                height: 50rem;
                 50rem;
                box-sizing: border-box;
                border:1px solid #00FFFF;
                margin:0 auto;
                position: relative;
            }
    
            .box {
                height: 100px;
                 100px;
                box-sizing: border-box;
                border:1px solid #00FFFF;
                position: absolute;
                left: 0;
                right: 0;
                top: 0;
                bottom: 0;
                margin: auto;
            }
        </style>

    第二种:

    <style type="text/css">
            .main_box {
                height: 50rem;
                 50rem;
                box-sizing: border-box;
                border:1px solid #00FFFF;
                margin:0 auto;
                position: relative;
            }
    
            .box {
                height: 100px;
                 100px;
                box-sizing: border-box;
                border:1px solid #00FFFF;
                position: absolute;
                left: 50%;
                top: 50%;
                margin-top: -50px;
                margin-left: -50px;
            }
        </style>

    第三种:

    <style type="text/css">
            .main_box {
                height: 500px;
                 500px;
                box-sizing: border-box;
                border:1px solid #00FFFF;
                margin:0 auto;
                position: relative;
            }
    
            .box {
                height: 100px;
                 100px;
                box-sizing: border-box;
                border:1px solid #00FFFF;
                position: absolute;
                left: 250px;
                top: 250px;
                margin-top: -50px;
                margin-left: -50px;
            }
        </style>

    第四种:

    <style type="text/css">
            .main_box {
                height: 500px;
                 500px;
                box-sizing: border-box;
                border:1px solid #00FFFF;
                margin:0 auto;
                position: relative;
            }
    
            .box {
                height: 100px;
                 100px;
                box-sizing: border-box;
                border:1px solid #00FFFF;
                position: absolute;
                left: 250px;
                top: 250px;
                transform: translate(-50%,-50%);
            }
        </style>

    第五种:

    <style type="text/css">
            .main_box {
                height: 500px;
                 500px;
                box-sizing: border-box;
                border:1px solid #00FFFF;
                margin:0 auto;
                position: relative;
            }
    
            .box {
                height: 100px;
                 100px;
                box-sizing: border-box;
                border:1px solid #00FFFF;
                position: absolute;
                left: 250px;
                top: 250px;
                transform: translate(-50px,-50px);
            }
        </style>

    第六种:

    <style type="text/css">
            .main_box {
                height: 500px;
                 500px;
                box-sizing: border-box;
                border:1px solid #00FFFF;
                margin:0 auto;
                position: relative;
            }
    
            .box {
                height: 100px;
                 100px;
                box-sizing: border-box;
                border:1px solid #00FFFF;
                position: absolute;
                left: 50%;
                top: 50%;
                transform: translate(-50px,-50px);
            }
        </style>

    第七种:

    <style type="text/css">
            .main_box {
                height: 500px;
                 500px;
                box-sizing: border-box;
                border:1px solid #00FFFF;
                margin:0 auto;
                position: relative;
            }
    
            .box {
                height: 100px;
                 100px;
                box-sizing: border-box;
                border:1px solid #00FFFF;
                position: absolute;
                left: 50%;
                top: 50%;
                transform: translate(-50%,-50%);
            }
        </style>

    第八种:

    <style type="text/css">
            .main_box {
                height: 500px;
                 500px;
                box-sizing: border-box;
                border:1px solid #00FFFF;
                margin:0 auto;
                display: flex;
                justify-content: center;
                align-items: center;
            }
    
            .box {
                height: 100px;
                 100px;
                box-sizing: border-box;
                border:1px solid #00FFFF;
                
            }
        </style>
  • 相关阅读:
    网站添加背景音乐
    解决项目上的红色感叹号
    1.12那些年你不知道的爬虫面试题
    1.11you-get 视频爬取
    1.10pytesseract
    1.9Pyppeteer
    1.8request-html
    1.7XPath
    1.6Selenium XPath
    1.5cookies
  • 原文地址:https://www.cnblogs.com/lxsunny/p/13791109.html
Copyright © 2011-2022 走看看