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;}

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

  • 相关阅读:
    常用的VI/VIM命令
    那些年学过的一些算法
    huffman编码
    好用java库(一):java date/time api:jodatime
    linux启动
    ubuntu学习方式
    地址
    各种各样的软件
    jquery文件
    C变量与数据
  • 原文地址:https://www.cnblogs.com/wangzhenyu666/p/7737828.html
Copyright © 2011-2022 走看看