1

私が達成しようとしているのは、画面の中央(720x360)にdivが中央に配置されたページです。これは、jQueryで以下を使用して行われます。

$(window).height()

と:

$(window).width()

これは完璧に機能します。

次の部分は、180x180の画像をその中央のdivに合わせて取得することです。これらは画面いっぱいに表示されます。

私はこれらをそのように整列させる方法に固執していて、同じことをしている人の実例を見つけることができませんでした。

それで、これも可能ですか?

4

1 に答える 1

0
<style type="text/css">

#main {
    display: block;
    margin:0 auto; /* This is make div into center of screen*/
    width: 720px;
    height: 360px;
    background: #ccc; /* Just for visibility */
    position: relative; /* As we want to make other div into center of this */
}

#content {
    display: block;
    width: 180px;
    height: 180px;
    position: absolute;
    left: 36.36%; /* You can calculate using math */
    /*
        Total Width - Width
        So you will get end point now minus half
        Width / 2 = 90
        Then 720 - 180 = 540
        And now your box will point to end but you need to divide
        half of width again 90/2 = 45
        Result is : 
        180/2/2 = 45
        720-180-45 = 495
        180/495*100 = 36.36
        So this is your width position.
    * */
    top: 25%;
    /*
    Same for height but as you can see it's 25% of your value and very easy
    * */
    background: red;
}


    </style>
    <div id="main">
   <div id="content"></div>
    </div>
于 2012-11-07T09:00:13.940 に答える