• CSS8种垂直居中方式


    1.通过vertical-align:middle实现垂直居中

      .son{

        display:inline-block;

        vertical-align:middle;

      }

    2.通过display:flex实现垂直居中

      .father{ display:flex; }

      .son{ align-self:center; }

    3.通过伪元素“:before”实现垂直居中

      .father{

                 500px;
                height:500px;
                "> blue;
                display: block;
            }
            .father:before{
                content: '';
                display:inline-block;
                vertical-align:middle;
                height: 100%;
            }
            .son{
                 200px;
                height: 200px;
                "> black;
                display:inline-block;
                vertical-align:middle;
      }
    4.通过dispaly:table-cell实现CSS垂直居中
      .father{ display:table; }
      .son{ 
      display:table-cell;
      vertical-align:middle; }
    5.通过隐藏节点实现CSS垂直居中
      .hide{ 
      50%;
      height:25%; }
      .son{ 
      50%;
      height:50%; }
    6.已知父元素高度通过transform实现CSS垂直居中
      .son{ 
      position:relative;
      top:50%;
      transform:translateY(-50%); }
    7.未知父元素高度通过transform实现CSS垂直居中
      .father{ 
      position:relative; }
      .son{ position:absolute;
      top:50%;
      transform:translateY(-50%); }
    8.通过line-height实现CSS垂直居中
      该方法适用于子元素为单行文本的情况
      .father{ height:300px; }
      .son{ line-height:300px; }
    ——学习记录
  • 相关阅读:
    Generator 函数的异步应用
    Generator 函数的语法
    10 个最佳的 Node.js 的 MVC 框架
    Node.js 框架对比之 Express VS Koa
    JavaScript资源分享
    【转载】Web 研发模式演变
    学习资源整理
    超高影响力开源大放送,学习开发必备教科书
    LVS + KEEPALIVED + WINDOWS SERVER 2008 R2 ------高可用负载均衡(转)
    LVS DR模式 RealServer 为 Windows 2008 R2配置
  • 原文地址:https://www.cnblogs.com/atao24/p/13278126.html
Copyright © 2020-2023  润新知