我有一个.wall
div
与其中的一些.toy
div
s。我想安排toy
s inside the wall
。 float:left
属性已经为我做好了。CSS中的绝对定位元素
现在的问题是我想为toy
div添加position:absolute
,以便以后可以拖动它。我怎么能通过Javascript或通过CSS来做到这一点?
应用position:absolute
,所有toy
旨意来到wall
覆的左上角和隐藏对方。
宽度和wall
的高度是恒定的,但toy
S的宽度和高度是可变的,也toy
div的数目是动态的,如数量增加toy
s need to arrange as rows。
任何暗示都会有帮助,请注意我无法避免使用position:absolute
进行拖拽。
<script type="text/javascript" src="jquery-1.4.2.min.js"></script>
<style>
body{
text-align:center;
}
.clearfix{
clear:both;
}
.wall {
border: 5px solid #cde;
margin:auto;
width:200px;
padding:10px;
}
.toy{
background-color: #BBCCEE;
border:1px solid #8899BB;
margin:5px;
width: auto;
padding:5px;
float:left;
}
.tall{
padding-top:10px;
}
</style>
<script>
$(document).ready(function() {
$('.toy').each(function(index) {
var position = $(this).offset();
var prevPosition = $(this).prev().offset();
$(this).css({
//top: position.top,
//left:position.left,
//position:'absolute',
});
});
});
</script>
<div class='wall'>
<div class='toy'>T1</div>
<div class='toy'>T2</div>
<div class='toy'>T3333333</div>
<div class='toy'>T4</div>
<div class='toy'>T5</div>
<div class='toy tall'>T6</div>
<div class='toy'>T7</div>
<div class='toy'>T8</div>
<div class='clearfix'></div>
</div>
的*** ***墙需要有相对位置,而不是玩具。下面似乎存在一个错误的交流。 * container *元素需要相对于绝对位置的位置来处理*内容*。你尝试过吗? – harpo 2010-06-28 17:25:04
是的,*墙*需要有位置相对和*玩具*需要有绝对位置 – 2010-06-29 03:31:16