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

    第一种方法 使用display: table;来实现垂直居中

    <div style="text-align: center;  500px;height:200px; display: table;border: green solid 1px;">
        <span style="display: table-cell; vertical-align: middle; "><img alt="" src="https://www.baidu.com/img/baidu_jgylogo3.gif" style="display: inline-block;" /></span>
    </div>

    第二种方法 使用绝对定位来实现垂直居中

    <div style=" 500px;height:200px; position: relative; border: green solid 1px;">
        <img alt="" src="https://www.baidu.com/img/baidu_jgylogo3.gif" style=" 120px; height: 40px;position: absolute; left:50%; top: 50%; margin-left: -60px;margin-top: -20px;" />
    </div>

    第三种方法 使用flex布局来实现垂直居中

    <div class="ui-flex justify-center center" style="border: green solid 1px;  500px; height: 200px;">
            <div class="cell">
            <img alt="" src="https://www.baidu.com/img/baidu_jgylogo3.gif" style="" />
            </div>
        </div>
    <style type="text/css">
            .ui-flex {
                display: -webkit-box !important;
                display: -webkit-flex !important;
                display: -ms-flexbox !important;
                display: flex !important;
                -webkit-flex-wrap: wrap;
                -ms-flex-wrap: wrap;
                flex-wrap: wrap
            }
    
            .ui-flex, .ui-flex *, .ui-flex :after, .ui-flex :before {
                box-sizing: border-box
            }
    
            .ui-flex.justify-center {
                -webkit-box-pack: center;
                -webkit-justify-content: center;
                -ms-flex-pack: center;
                justify-content: center
            }
            .ui-flex.center {
                -webkit-box-pack: center;
                -webkit-justify-content: center;
                -ms-flex-pack: center;
                justify-content: center;
                -webkit-box-align: center;
                -webkit-align-items: center;
                -ms-flex-align: center;
                align-items: center
            }
        </style>
  • 相关阅读:
    技术文章应该怎么写?
    后退时保存表单状态
    [原]长表头表格 竖直仅滚动内容区 水平滚动表头和内容区
    IE7不经提示关闭浏览器窗口
    meta 标记
    demo : 简单的 xslt 递归解析 xml 成 tree
    使用iframe和table模拟frameset的resize功能.html
    一个下划线(_)引发的"疑难杂症"
    几点小东西
    使用 ActiveReports 的 subReport 几点疑惑
  • 原文地址:https://www.cnblogs.com/sure2016/p/7986170.html
Copyright © 2011-2022 走看看