利用css如何讓div處於永遠置中狀態?

來源:互聯網
上載者:User
不管螢幕如何滑動,該p始終保持在螢幕正中央(支援IE7(包括IE7)以上版本)

下面介紹的這段簡單的代碼就可以實現這個功能,請大家可以來參考一下。

<p class="loginBox"></p>

css部分應該這樣子寫:

.loginBox {    background: #FA2;    width: 700px;    height: 400px;    position: fixed;    left: 50%;    top: 50%;    z-index: 11;    /*設定這個p的margin-top的負值為自身的高度的一半,margin-left的值也是自身的寬度的一半的負值.*/     /*寬為400,那麼margin-top為-200px*/     /*高為200那麼margin-left為-100px;*/     margin: -200px 0 0 -350px;}

寫完了,就這麼簡單,是不是感覺想不到呢。

【相關推薦】

1. 免費css線上視頻教程

2. css線上手冊

3. php.cn獨孤九賤(2)-css視頻教程

相關文章

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.