开发者

set 5 divs in the same positions jquery

How can I set the location of 5 divs (equally in dimension) in the same position after initializing with jQuery.

The reason I want to have this is to mov开发者_开发知识库e them one by one to another div.

Thanks in advance.


It depends largely on the HTML you have, but the general ideal is to set the CSS position attribute of each element to be absolute, and then set their positions to be the same using a combination of the top, left, bottom and right CSS properties.

$('yourDivs').css({
    position: 'absolute',
    top: 0,
    left: 0
});

This assumes that the the div's are in the same parent, or that none of their ancestors has a position: relative attribute.


Something like this? http://jsfiddle.net/Gab4B/

div
{
 height: 200px;
  width: 200px;  
}

div div {
 height: 20px;
  width: 20px;  
    border: solid 1px black;
}
div.seperate-equal
{
    position: absolute;
    top: 0;
    left: 0;
 height: 5px;
  width: 5px;
   background-color: red; 
}


Set CSS position: absolute, with equal top and left...


You'll need some position absolute. Demo at JS Fiddle

$('.class').each(function(){ 
    this.style.top=0; 
    this.style.left=0; 
    this.style.position='absolute'
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜