• css元素居中方法


    几种居中方式,分情况使用:

    1.已知父盒子宽度,子盒子宽度;

    div{

       transform: translate(-50%,-50%);

       //margin-left: - 自身宽度一半;

       position: absolute;

       left: 50%;

       top: 50%;

    }

    2.div标签下img标签参考span元素;

    img{

       vertical-align: middle;

    }

    span{

       display: inline-block;

       height: 100%;

       vertical-align: middle;

    }

    div:after{

       content: "";

       display: inline-block;

       height: 100%;

       vertical-align:middle;

    }

    3.利用表格table;div下的span

    div{

        display:table;

    }

    span{

        text-align:center;

        vertical-align: middle;

        display: table-cell;

    }

    4.流式布局居中,div下的span;

    div{

         display:flex;

    }

    span{

          margin: auto;

    }

    5.div包含ul,ul宽度不确定,li宽度不确定,个数不确定;

    .slideBox .hd {
          position: relative;
          *text-align: center;
          margin-top: -20px;
          z-index: 23;
    }
    .slideBox .hd ul {
          display:table;
          margin-left:auto;
          margin-right:auto;
          margin-top: -50px;
          margin-bottom: 20px;
    }
    .slideBox .hd ul li {

          143px;
          height: 32px;
          margin-right: 10px;
          cursor: pointer;
          background-color: rgba(255, 255, 255, .5);

          border-radius: 4px;

    /* ================= */
          float:left;
         *float:none;
         *display:inline;
         *zoom:1;
          z-index: 20;
    }

    示例效果如下:

  • 相关阅读:
    Python必须知道的异常处理
    类的内置方法(用实际代码来验证)
    类的三大特性(继承, 封装, 多态)
    面向对象编程代码详解(依赖关系,关联关系,组合关系)
    函数(匿名函数,嵌套函数,高阶函数,装饰器)
    常用模块
    对磁盘文件的操作(文件处理)
    字符编码
    常用数据类型
    编程介绍
  • 原文地址:https://www.cnblogs.com/bug-master/p/6178262.html
Copyright © 2020-2023  润新知