zoukankan      html  css  js  c++  java
  • 常用的居中方法

    整理下常用的居中方法

    1.采用  display:flex 方法

    #box1{height: 200px;background: #09c;margin:20px 0;width: 500px;display: flex;justify-content:center;align-items:center;}
    #content1{width: 100px;height: 100px;background: yellow;}

    2.采用  display:table-cell  方法

    #box2{height: 200px;background: #09c;margin:20px 0;width: 500px;display:table-cell;vertical-align:middle;text-align: center;}
    #content2{display: inline-block;width: 100px;height: 100px;background: yellow;}

    需要注意的是第二种方法如果子元素为块级标签的话,需要设置其 display:inline-block; ,转为行块级标签

    3.采用定位方法

    #box3{height: 200px;background: #09c;margin:20px 0;width: 500px;position: relative;}
    #content3{width: 100px;height: 100px;background: yellow;position:absolute;top:0;right:0;bottom:0;left:0;margin:auto;}

    或者

    #content3{width:Xpx;height:Ypx;position:absolute;top:50%;left:50%;margin:-Y/2px 0 0 -X2px;}

    如有表述不准确之处,欢迎指正,欢迎补充,感谢阅读。

  • 相关阅读:
    Hibernate的检索
    Java 多线程
    可信软件开发
    Linux复习3
    Linux复习2
    Linux复习1
    使用Sourcetree(for windows)建立github同步仓库
    Session技术
    Cookie技术
    Ajax技术
  • 原文地址:https://www.cnblogs.com/wangzhenyu666/p/7737828.html
Copyright © 2011-2022 走看看