• css元素水平垂直居中


    温习一下元素水平垂直居中的几种方法

    元素有具体宽度

    1、absolute+负边距

    .LV_center{
      border: 1px solid red;
      position: absolute;
       100px;
      height: 100px;
      top:50%;
      left: 50%;
      margin-top:-原高度/2 ;
      margin-left: -原高度/2
    }

    2、absolute+calc

    .LV_center{
      border: 1px solid red;
      position: absolute;
       100px;
      height: 100px;
      top:calc(50% - 原高度/2);
      left:calc(50% - 原高度/2);
    }

     3、absolute+margin auto

    .LV_center{
      border: 1px solid red;
      position: absolute;
       100px;
      height: 100px;
      top: 0;
      left: 0;
      bottom: 0;
      right: 0;
      margin: auto;
    }

    元素宽度不定

    1、absolute+transform,css3特性2d平移

    .LV_center{
      border: 1px solid red;
      position:absolute;
      top:50%;
      left:50%;
      transform:translate(-50%,-50%);
    }

    2、line-height,外层设置行高,内层继承行高

    .box{
      line-height: 300px;
    }
    .LV_center{
      border: 1px solid red;
      display: inline-block;
      line-height: inherit;
      vertical-align: middle;
    }

    3、table-cell,模拟td特性,让元素像表格里的td

    .box{
      border: 1px solid red;
       300px;
      height: 300px;
      display: table-cell;
      text-align: center;
      vertical-align: middle;
    }
    .LV_center{
      border: 1px solid red;
      display: inline-block;
    }

    4、flex弹性盒子

    .LV_center{
    border: 1px solid red;
      display: flex;
      justify-content: center;  //主轴对齐方式
      align-items: center;  //位于主轴中心
    }

    推荐一位讲得更详细的 : https://www.jianshu.com/p/1b3337214941

  • 相关阅读:
    TestNG之Factory
    Selenium2怎么调用selenium1中方法
    JAVA如何随机生成一个汉字
    selenium如何随机选取省份和城市的下拉框的值
    Bootstrap之登陆页面范例
    Bootstrap之信息记录
    Bootstrap之表格、表单应用
    Bootstrap之响应式导航栏
    Bootstrap之网格类
    使用fastjson将对象和字符串进行转换
  • 原文地址:https://www.cnblogs.com/tenfly/p/11446479.html
Copyright © 2020-2023  润新知