热门标签 | HotTags
当前位置:  开发笔记 > 前端 > 正文

如何将元素固定在水平滚动div中

如何解决《如何将元素固定在水平滚动div中》经验,为你挑选了1个好方法。



1> Loïc Bellema..:

位置fixed无效,因为它总是相对于页面。您想将元素嵌套在另一个具有position的组件中relative。内部元素将基于该父元素定位。

.top-container {
    position: relative;
    width: 20rem;
    border: 1px solid grey;
}

.container {
    padding: 1rem 1rem;
    overflow-x: auto;
    margin: 0;
}
.top-container button {
    position: absolute;
    right: 0;
    top: 0;
}
Long piece of content that overflows the width of container

推荐阅读
author-avatar
冬眠2502917261
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有