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

    方法1(margin: 0 auto)
    <!
    DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>css浮动盒子居中</title> <style> *{ margin: 0; padding: 0; list-style: none; } body{ background: #fffccc; text-align: center; } .box{ background-color: red; display: inline-block; } </style> </head> <body> <div class="box"> 我是浮动的盒子 我要居中 </div> </body> </html>

    方法2(inline_block)

     body{
                background: #fffccc;
         }
     .box{
                background-color: red;
                width: 30%;
                margin: 0 auto;
          }

    方法三(flew)

     body {
                background: #fffccc;
                display: flex;
                justify-content: center;
                height: 300px;
            }
            .box {
                background-color: red;
                width: 30%;
                margin: 0 auto;
    
            }
    盒子要有高度不然其高度与父级一致

    方法四 (浮动或者定位)

     body {
                background: #fffccc;
                height: 300px;
            }
       .box {
                background-color: red;
                width: 30%;
                float: left;
                margin-left:  50%;
                transform: translateX(-50%);
    
         }

  • 相关阅读:
    pygame--颜色变化
    pyQt绘图
    pyqt布局管理器
    java执行shell/cmd命令
    word公式编辑器公式
    pygame绘制文本
    2.add two number
    eltwise层
    crop层
    fcn
  • 原文地址:https://www.cnblogs.com/aqigogogo/p/8028093.html
Copyright © 2011-2022 走看看