[英]aligning div by reference of a div
我正在嘗試對齊位於所有div底部的div。
最后一個div是浮動div,並按CSS對齊到頂部。
我不知道如何在不改變屏幕分辨率的情況下從左側對齊它。 如果可能的話,請告訴我是否可以給一個div的ID,該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>
謝謝
好吧,如果我對您的理解正確,並且想對頂部和底部的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;
}
用戶jquery偏移量
http://api.jquery.com/offset/
接着
var offsetval=$('#relativediv').offset()
$('#bottom_div').css('left',offsetval.left);// change left value the way you want
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.