zoukankan      html  css  js  c++  java
  • 盒子垂直居中方式

    最通用的盒子垂直居中方式

    1. absolute + translate

    html :

    <div class="wrap">
        <main>
            <blockquote> “n the event of a large-scale natural...
                <footer>— <cite> Oscar Wilde, The Picture of Dorian Gray </cite></footer>
            </blockquote>
        </main>
    </div>
    

    css :

    .wrap{
            100%;
            height: 100%;
            position: relative;
            /*overflow: hidden;*/
            background: url("../images/tiger.jpg") 0 / cover fixed;
        }
        main {
             600px;
            height: 240px;
            border-radius: 8px;
            padding: 20px 10px;
            text-align: justify;
            position:absolute;
            left:50%;
            top:50%;
            -webkit-transform: translate(-50%, -50%);
            -moz-transform: translate(-50%, -50%);
            -ms-transform: translate(-50%, -50%);
            -o-transform: translate(-50%, -50%);
            transform: translate(-50%, -50%);
            background: hsla(0, 0%, 100%, .3);
        }
    

    2.absolute +margin

    .wrap{
            100%;
            height: 100%;
            position: relative;
            background: url("../images/tiger.jpg") 0 / cover fixed;
        }
        main {
             600px;
            height: 240px;
            border-radius: 8px;
            padding: 20px 10px;
            text-align: justify;
            position: absolute;
            left: 0;
            right: 0;
            top: 0;
            bottom: 0;
            margin: auto;
        }
  • 相关阅读:
    Visual Studio2019安装步骤
    写在第一页的话
    数状数组
    hdu 3501 数学题
    静态邻接表
    最长子序列
    hdu 1094 所想到的
    bellman_ford
    郁闷的一晚
    SPFA + 静态邻接表 模板
  • 原文地址:https://www.cnblogs.com/king-ying/p/6484841.html
Copyright © 2011-2022 走看看