zoukankan      html  css  js  c++  java
  • 524 垂直居中布局:table-cell+vertical-align,绝对定位position,flex + align-items





    垂直居中布局解决方案1 - table-cell+vertical-align

    <!DOCTYPE html>
    <html lang="en">
    
    <head>
      <meta charset="UTF-8">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <meta http-equiv="X-UA-Compatible" content="ie=edge">
      <title>垂直居中布局解决方案1 - table-cell+vertical-align</title>
      <style>
        * {
          margin: 0;
          padding: 0;
        }
    
        #parent {
           200px;
          height: 600px;
          background: #ccc;
        }
    
        #child {
           200px;
          height: 200px;
          background: #c9394a;
    
          /* 垂直居中 */
          line-height: 200px;
        }
      </style>
    </head>
    
    <body>
      <!-- 定义父级元素 -->
      <div id="parent">
        <!-- 定义子级元素 -->
        <div id="child">水平垂直居中布局</div>
      </div>
    </body>
    
    </html>
    

    垂直居中布局解决方案2 - 绝对定位position

    <!DOCTYPE html>
    <html lang="en">
    
    <head>
      <meta charset="UTF-8">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <meta http-equiv="X-UA-Compatible" content="ie=edge">
      <title>垂直居中布局解决方案2 - 绝对定位position</title>
      <style>
        * {
          margin: 0;
          padding: 0;
        }
    
        #parent {
           200px;
          height: 600px;
          background: #ccc;
          position: relative;
        }
    
        #child {
          /* 定位 - 参照物 父元素 */
           200px;
          height: 200px;
          background: #c9394a;
          position: absolute;
          top: 50%;
          /* margin-top:-100px; */
          transform: translateY(-50%);
        }
      </style>
    </head>
    
    <body>
      <!-- 定义父级元素 -->
      <div id="parent">
        <!-- 定义子级元素 -->
        <div id="child"></div>
      </div>
    </body>
    
    </html>
    

    垂直居中布局解决方案3 - flex + align-items

    <!DOCTYPE html>
    <html lang="en">
    
    <head>
      <meta charset="UTF-8">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <meta http-equiv="X-UA-Compatible" content="ie=edge">
      <title>垂直居中布局解决方案3 - flex + align-items</title>
      <style>
        * {
          margin: 0;
          padding: 0;
        }
    
        #parent {
           200px;
          height: 600px;
          background: #ccc;
    
          display: flex;
          /* 垂直排列 */
          align-items: center;
        }
    
        #child {
           200px;
          height: 200px;
          background: #c9394a;
        }
      </style>
    </head>
    
    <body>
      <!-- 定义父级元素 -->
      <div id="parent">
        <!-- 定义子级元素 -->
        <div id="child"></div>
      </div>
    </body>
    
    </html>
    

  • 相关阅读:
    c# 读改xml
    window
    c# 日期字符格式化
    验证字符串是否为数字
    MySQL常用操作基本操作
    将参数扩展为指定长度的字符串,不足位数的在前方加0
    hp服务器重装后,启动apache和tomcat和mysql
    [转] 各种取整数函数(VB)
    [原] access97中textbox类似vb的maxlength功能的实现
    [转] csv文件的读写
  • 原文地址:https://www.cnblogs.com/jianjie/p/13771313.html
Copyright © 2011-2022 走看看