zoukankan      html  css  js  c++  java
  • 垂直居中

     1 .line-height方式

    <style>
    #d {
    line-height: 100px;
    } 
    div{
      border:solid 1px lightskyblue;
    }
    </style>
    
    <div id="d">line-height 适合单独一行垂直居中</div>

    2.内边距方式

    借助设置相同的上下内边距,实现垂直居中效果,可以用在多行文本上

    <style>
    #d {
        padding: 30 0;
    }
    div{
         border:solid 1px lightskyblue;
    }
    </style>
    
    <div id="d">多行内容 多行内容 多行内容 多行内容 多行内容 多行内容 多行内容 多行内容 多行内容 多行内容 多行内容 多行内容 多行内容 多行内容 多行内容 多行内容 多行内容 多行内容 多行内容 多行内容 多行内容 多行内容 多行内容 多行内容 多行内容 多行内容 多行内容 多行内容 多行内容 多行内容 多行内容 多行内容 多行内容 多行内容 多行内容 多行内容 多行内容 多行内容 多行内容 多行内容  </div>

    3.table方式

    首先通过display: table-cell;把div用单元格的形式显示,然后借用单元格的垂直居中vertical-align: middle; 来达到效果。
    这样对图片也可以居中,上一步 line-height就不能对图片居中。

    <style>
    #d {
    display: table-cell;
    vertical-align: middle;
    height:200px;
    }
    
    div{
      border:solid 1px lightskyblue;
    }
    </style>
     
    <div id="d">
    <img src="http://how2j.cn/example.gif">
    </div>

  • 相关阅读:
    使用OpenCV进行相机标定
    近景摄影测量
    vmware安装操作系统
    mac下使用gnu gcc
    Collection of Boot Sector Formats for ISO 9660 Images
    java会不会出现内存泄露
    difference between http get and post
    Apache许可翻译
    项目持续集成工具
    常用的地图投影算法
  • 原文地址:https://www.cnblogs.com/thiaoqueen/p/6876378.html
Copyright © 2011-2022 走看看