相容IE6,IE7,IE8,Firefox,Chrome,DIV+CSS垂直置中終於失敗,最後三分鐘用寫了幾行JS解決,經簡單測試,還行。

來源:互聯網
上載者:User

先上Jquery的代碼,保留備用。

function verticalCenter() {var wapperHeight = $("#wapper").height();var windowHeight = $(window).height();var wapperTop = windowHeight > wapperHeight ? Math.round((windowHeight - wapperHeight) / 2) : 0;$("#wapper").css("margin-top", wapperTop + "px");}$(document).ready(function () {    $(window).resize(verticalCenter);    verticalCenter();});

只要最外層用<div id="wapper"> …… </div>包裹住就行了。

以下是牢騷,TMD的相容性啊,我看HTML5之後更TMD的亂~

相關文章

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.