CSS 水平垂直居中

</head>

<style>

    #bl{
        position: relative;
    }
    .kk{
      height: 100px;
       width: 500px;
    }
    .f1{
       font-size: 26px;
    }

    .d1{
       background: rgb(101, 165, 42);
    }
    .s1{
        line-height: 100px;
    }

    .d9{
       background: rgb(116, 42, 165);
       text-align: center;
    }
    .s9{
        /* display: inline; */
    }

    .d10{
       background: rgb(21, 109, 26);
       position: relative;
    }
    /* 在已知长度的情况下margin一半的长度 */
    .s10{
        position: absolute;
        left: 50%;
        margin-left: -70px;
    }

    .d11{
       background: rgb(10, 44, 236);
       display: flex;
       justify-content: center;

    }
    .s11{

    }

    .d2{
       background: rgb(165, 153, 42);
       position: relative;
    }
    .s2{
        position: absolute;
        left: 50%;
        transform: translateX(-50%);
    }

    .d12{
       background: rgb(233, 156, 12);
       display: table-cell;
       vertical-align:middle;

    }
    .s12{
       
    }

    .d13{
       background: rgb(9, 16, 105);
       position: relative;
    }
    /* 在已知高度的情况下margin一半的长度 */
    .s13{
       position: absolute;
       top: 50%;
       margin-top: -22px;
    }

    .d14{
       background: rgb(238, 14, 238);
       position: relative;
    }
    .s14{
       position: absolute;
       top: 50%;
       transform: translateY(-50%);
    }

    .d15{
       background: rgb(9, 240, 190);
       position: relative;
       display: flex;
       align-items: center;
    }
    .s15{
       
    }

    .d3{
       background: rgb(42, 120, 165);
       text-align: center;
    }
    .s3{
       line-height: 100px;
    }

    .d4{
       position: absolute;
       background: rgb(165, 61, 42);
       text-align: center;
       /* 垂直居中 */
       top:0;
       right:0;
       left:0;
       bottom:0;
       margin:auto;
    }
    .s4{
       line-height: 100px;
    }

    .d5{
       background: rgb(140, 42, 165);
       text-align: center;
       top:0;
       right:0;
       left:0;
       bottom:0;
       margin:auto;
    }
    .s5{
       line-height: 100px;
    }

    .d6{
       background: rgb(178, 241, 75);
       text-align: center;
       position: absolute;
       top: 50%;
       left: 50%;
       transform: translate(-50%,-50%);
    }
    .s6{
       line-height: 100px;
    }

    .d7{
       background: rgb(140, 42, 165);
       text-align: center;
       display: grid;
       
    }
    .s7{
       line-height: 100px;
       align-self: center;
       justify-self: center;
    }

    .d8{
       background: rgb(165, 42, 83);
       text-align: center;
       position: absolute;
       top: 50%;
       left: 50%;
       /* 分别为宽和高的一半 */
       margin-left: -250px;
       margin-top: -50px;
       
    }
    .s8{
       line-height: 100px;
    }

</style>
<body>
    <div id="bl">
        <!--div中文字水平居中-->
        <div class="d1 kk">
        <span class="s1 f1">ABCDEFG1</span>
        </div>
        <div class="d9 kk">
         <span class="s9 f1">ABCDEFG9</span>
         </div>
        <div class="d10 kk">
         <span class="s10 f1">ABCDEFG10</span>
         </div>
        <div class="d11 kk">
         <span class="s11 f1">ABCDEFG11</span>
         </div>


        <!-- div中文字垂直居中 -->
        <div class="d2 kk">
        <span class="s2 f1">ABCDEFG2</span>
        </div>
        <div class="d12 kk">
         <span class="s12 f1">ABCDEFG12</span>
         </div>
        <div class="d13 kk">
         <span class="s13 f1">ABCDEFG13</span>
         </div>
        <div class="d14 kk">
         <span class="s14 f1">ABCDEFG14</span>
         </div>
        <div class="d15 kk">
         <span class="s15 f1">ABCDEFG15</span>
         </div>


        <!-- div中文字垂直水平居中 -->
        <div class="d3 kk">
        <span class="s3 f1">ABCDEFG3</span>
        </div>
        

        <!-- div水平居中 -->
        <div class="d5 kk">
         <span class="s5 f1">ABCDEFG5</span>
         </div>


        <!-- div垂直水平居中 -->
        <div class="d4 kk">
        <span class="s4 f1">ABCDEFG4</span>
        </div>
        <div class="d6 kk">
        <span class="s6 f1">ABCDEFG6</span>
        </div>
        <div class="d7 kk">
        <span class="s7 f1">ABCDEFG7</span>
        </div>
        <div class="d8 kk">
        <span class="s8 f1">ABCDEFG8</span>
        </div>

    </div>
</body>

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值