html - div 在另一个 div 上方的固定或粘性位置
问题描述
我在底部有一个高度取决于其中的数据的 div,所以我不知道底部 div 的确切高度。
<div id="BottomOfPage">I don't know exactly height this div</div>
问题,我需要另一个 div 位置粘滞或固定在 id="BottomOfPage"
<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"
解决方案
我试试这个
<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个多小时,在我提交这个问题后,我得到了答案。还是非常感谢。
推荐阅读
- mysql - 在Sql中加入之间时如何用例
- ruby - 电子表格 gem 错误访问 Excel 文件的多个工作表
- c - Linux中chattr的替代方法
- c# - 使用异步与实体框架选择 IQueryable 类型的列表
- java - java,为什么会出现这些错误?--maven-compiler-plugin:3.7.0
- php - 从索引数组中删除一个元素
- r - 在不同时间间隔具有多个系列的 Dygraph
- google-cloud-endpoints - 在 Google Kubernetes Engine 上获取部署失败的 Google Endpoints
- java - 无法使用 Java 读取 XML 文档
- php - Laravel - GroupBy 作为别名