通过引用div来对齐div

时间:2010-12-07 07:42:27

标签: css html

我试图对齐一个位于所有div底部的div。

最后一个div是浮动div并通过css对齐到顶部。

我不知道如何从左侧对齐它而没有任何屏幕分辨率变化的问题。如果可能的话请告诉我是否可以给出一个div的id,其位置总是固定的,并且在css的帮助下离开该div的距离。

<div id='fixeddiv'>this div is at the top</div>
<div> rest of the divs </div>
<div> rest of the divs </div>
<div> rest of the divs </div>
<div> rest of the divs </div>
<div> rest of the divs </div>
<div> rest of the divs </div>
<div id='bottom_div'>this div is floating</div>

由于

2 个答案:

答案 0 :(得分:1)

好吧,如果我理解正确并且您希望将一个左对齐分配给顶部和底部div,另一个分配给其余div,请使用类:

<div id='fixeddiv' class='header-and-footer'>this div is at the top</div>
<div class='other-content'> rest of the divs </div>
<div class='other-content'> rest of the divs </div>
<div class='other-content'> rest of the divs </div>
<div class='other-content'> rest of the divs </div>
<div class='other-content'> rest of the divs </div>
<div class='other-content'> rest of the divs </div>
<div id='bottom_div' class='header-and-footer'>this div is floating</div>

的CSS:

.header-and-footer {
    margin-left: 50px;
}

.other-content { 
    margin-left: 10px;
}

或:

div { 
    margin-left: 10px;
}

div.header-and-footer {
    margin-left: 50px;
}

答案 1 :(得分:0)

用户jquery偏移量

http://api.jquery.com/offset/

然后

var offsetval=$('#relativediv').offset()

$('#bottom_div').css('left',offsetval.left);// change left value the way you want