2011-02-10 27 views
2
<!--container with jQuery UI draggable , resizable plugins applied--> 
<div class="container"> 
    <div class="stayInCenter" style="position:absolute;width:300px; height:400px"> 
     I will aways stay in center of the container no matter where you are 
     and how big or small you become 
    </div> 
</div> 

回答

3

如果您不需要垂直居中:

.container .stayInCenter {  
    position:relative; /* Not absolute */ 
    margin:0 auto  /* Make the left/right be centered */ 
} 

如果您確實需要垂直居中也:

.container .stayInCenter {  
    position:absolute; 

    /* Move to the center of the positioned parent */ 
    left:50%; top:50%; 

    /* Give a fixed size */ 
    width: 300px; height: 400px; 

    /* Move backwards by half the size, so the center is at 50% */ 
    margin-left:-150px; margin-top:-200px; 
} 

此外,don't mix CSS with your HTML

+0

但是在應用了JQuery UI可拖動插件後,容器的位置將被設置爲絕對永遠! – qinHaiXiang 2011-02-10 15:22:19

0

你把一個固定的寬度,讓我們說的「width:500px的」
,你把「保證金:汽車」

如果你需要一個上邊距,你寫如。 'margin-top:100px''margin:auto'

應該完成這項工作

相關問題