zoukankan      html  css  js  c++  java
  • 如何垂直居中一个浮动元素

    如何垂直居中一个浮动元素

    // 方法一:已知元素的高宽

    #div1{

        

        200px;

        height:200px;

        position: absolute;        /*父元素需要相对定位*/

        top: 50%;

        left: 50%;

        margin-top:-100px ;   /*二分之一的height,width*/

        margin-left: -100px;

        }

     

    //方法二:未知元素的高宽

     

      #div1{

         200px;

        height: 200px;

        

     

        margin:auto;

        position: absolute;        /*父元素需要相对定位*/

        left: 0;

        top: 0;

        right: 0;

        bottom: 0;

        }

    /*如何垂直居中一个<img>(用更简便的方法。)*/

    #container     /*<img>的容器设置如下*/

    {

        display:table-cell;

        text-align:center;

        vertical-align:middle;

    }

  • 相关阅读:
    支付宝沙箱环境应用
    七牛云视频托管
    腾讯云短息验证码接口
    git远程连接(码云)
    git
    字间距
    html文本保留空格
    mysql重启导致AUTO_INCREMENT从1开始
    js保留两位小数
    vue中watch的基本用法
  • 原文地址:https://www.cnblogs.com/Coding--Peasant/p/7071355.html
Copyright © 2011-2022 走看看