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>
Phrogz
  • 296,393
  • 112
  • 651
  • 745
qinHaiXiang
  • 6,051
  • 12
  • 47
  • 61

2 Answers2

3

If you don't need vertical centering:

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

If you do need vertical centering also:

.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;
}

Also, don't mix CSS with your HTML.

Phrogz
  • 296,393
  • 112
  • 651
  • 745
0

you put a fixed width, let's say 'width:500px'
and you put 'margin:auto'

if you need a top margin, you write eg. 'margin-top:100px' after the 'margin:auto'

should do the job

Mash
  • 1,339
  • 7
  • 8