我的底部有一个div,其高度取决于其中的数据,因此我不完全知道底部的div高度。
<div id="BottomOfPage">I don't know exactly height this div</div>
问题,我需要在id =“ BottomOfPage”上方放置一个位置固定或固定的div
<div id="StickyOrFixed">image link</div>
<div id="BottomOfPage">i don't know exactly height this div</div>
我尝试过,但仍然无法解决此问题,我搜索了类似的问题,但找不到,也许我错过了。请帮忙,谢谢。
我尝试
#StickyOrFixed{margin-bottom:20px;position:sticky;}
#StickyOrFixed{margin-bottom:20px;position:fixed;}
不起作用,它需要顶部或底部位置,但我不知道确切的高度id =“ BottomOfPage”
答案 0 :(得分:0)
我试试这个
<div id="StickyOrFixed" style="position:sticky;bottom:50px;margin-bottom:20px;">image link</div>
<div id="BottomOfPage">i don't know exactly height this div</div>
它解决了我所需要的,如果div id =“ BottomOfPage”高度为100px,仍粘在id =“ BottomOfPage”之上,并且margin-bottom:20px; 。滚动粘滞后始终从底部开始50px。
我尝试这个过程超过2个小时,提交问题后,我得到了答案。还是谢谢你。
答案 1 :(得分:0)
<div style="position:sticky;bottom:20px;" align="center">
<div style="width:980px;" align="right">
<div style="float:right;bottom:100px;position:relative;">image link</div>
</div>
</div>
<div id="BottomOfPage">i don't know exactly height this div</div>
这将在div id =“ BottomOfPage”上方20px,并且如果从底部开始100px从高度id =“ BottomOfPage”开始滚动 980px中间的粘性位置