CSS彈窗置中的實現方法

來源:互聯網
上載者:User
下面為大家帶來一篇彈窗置中的簡單實現方法。內容挺不錯的,現在就分享給大家,也給大家做個參考。

最近做頁面的時候經常會遇到彈出框置中的問題,

請教了一下身邊的大牛,終於弄出來了,

實現的原理:

1,給外圍盒子定義一個偽類:before

2,外圍盒子定義fixed屬性

3,定義內容盒子。

定義外圍盒子:

outbox{      position:fixed;      top:0;      rightright:0;      bottombottom:0;      left:0;      display:block;      text-align:center;   }

定義外圍盒子偽類:

outbox:before{      content="";      width:0;      height:100%;      display:inline-block;      vertical-align:middle;   }

定義內容盒子:

contentbox{       display:inline-block;       vertical-align:middle;       text-align:center;    }

全部代碼:

<!doctype html><html>    <head>        <meta charset="utf-8">        <meta name="viewport" content="width=device-width,initial-scale=1">        <title>彈窗置中</title>        <style type="text/css">            .outbox:before{                   content:"";                   width:0;                   height:100%;                   display:inline-block;                   vertical-align:middle;               }               .outbox{                   position:fixed;                   top:0;                   right:0;                   bottom:0;                   left:0;                   text-align:center;               }               .content{                   width:200px;                   height:200px;                   background-color:#ccc;                   display:inline-block;                   vertical-align:middle;               }           </style>    </head>    <body>    <p class="outbox">        <p class="content">        </p>    </p>    <body></html>

以上就是本文的全部內容,希望對大家的學習有所協助,更多相關內容請關注topic.alibabacloud.com!

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.