javascript - 将绝对定位的粘性元素与兄弟内部的 div 对齐?
问题描述
假设我有以下博客文章设置:
<div>
<div> //this div has some margin left & right, so the blog post is centered
<div>Title</div>
<div>Body</div>
</div>
<ContainerAbsolute> //inside the right margin, i absolutely position this container & the sticky side bar inside it.
<StickySideBar />
</ContainerAbsolute>
</div>
我希望我的 StickySideBar 位于右侧并沿着博客文章向下。我用position:sticky
它。我已将它放入一个容器中,该容器绝对定位,并延伸到整个页面 ( height: 100%
)。现在可以了。但现在我希望我的 StickySideBar 被卡在我的 Text 开始的位置,而不是最上面。我可以做top: 500px
类似的事情来近似这个,但我怎样才能将它与Body
div 完美对齐?
解决方案
推荐阅读
- android - Gradle 在 iOS 模块中找不到带有 libGDX 的核心项目
- css - transform 属性的 CSS 过渡,但具有不同的模式
- php - 部署后如何在 Google App Engine Standard 上运行 Laravel 迁移
- ios - 我是否可以在 iOS 中导入 uikit 和基础框架?
- c++ - 如何包含
- docker - 为什么我的 docker-compose 端口配置有效?
- reactjs - 有没有办法在 Create React App 应用程序中按顺序运行笑话测试?
- c++ - 有人可以告诉我我的代码有什么问题吗?
- python - 如何使用简单的“for”循环自动将多个文件加载到 numpy 数组中?
- android - 仅在数据更新时调用的 Firebase 事件监听器