簡體   English   中英

對齊/環繞div圖像

[英]Align/Wrap images around div

我想要實現的是一個div位於屏幕中間(720x360)中心的頁面。 這是使用jQuery完成的:

$(window).height()

和:

$(window).width()

完美地工作。

下一部分將獲得180x180的圖像以適合該中間div。 這些將填滿屏幕+。

我一直在堅持如何使它們保持一致的方式,而我找不到任何人在做相同事情的真實例子。

那么,這可能嗎?

<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>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM