html - 在 overflow-x: auto 中定位绝对 div
问题描述
我正在尝试absolute
div
使用overflow-x: auto
简而言之,场景是这样的:
<div style="overflow-x: auto">
<div style="position: relative">
<div style="position: absolute">
I'm not absolute :(
</div>
</div
</div>
我使用tailwindcss https://jsfiddle.net/fhp64ztv/2/做了一个最小的例子
现在,我有两个结果:
编辑因为我必须添加一个堆栈片段:
<nav class="nav bg-white flex items-center shadow justify-between flex-wrap p-6 sticky top-0 z-10">
<div class="nav-content w-full flex-grow max-h-screen">
<a href="#" class="nav-item block">Docs</a>
<a href="#" class="nav-item block">Examples</a>
<a href="#" class="nav-item block"> Blog</a>
<div class="nav-item dropdown relative mt-4">
<button class="text-indigo-500 inline-block">
Profile
</button>
<div class="dropdown-items bg-white border absolute left-auto mt-2 py-2 z-50">
<a href="#" class="dropdown-item block px-4 py-2">Account settings</a>
<a href="#" class="dropdown-item block px-4 py-2">Support</a>
<a href="#" class="dropdown-item block px-4 py-2">Sign out</a>
</div>
</div>
</div>
</nav>
.nav-content {
/* I want it to look like this */
/*overflow-y: visible; */
/* But I need this to scroll in the navbar */
overflow-y: auto;
}
解决方案
推荐阅读
- mysql - 为什么 Master 上的 GTID 与 Slave 上的 GTID 不同,而两者都同步(MariaDB 10.5)?
- sql - 像 Hive 的 LATERAL VIEW STACK 这样的非透视数据的 Snowflake 替代方案是什么?
- javascript - 阿波罗客户端 offsetLimitPagination 不起作用
- javascript - 有没有办法访问我的响应错误消息?
- java - 如何通过maven在tomee应用程序中从源代码和静态负载构建java代理?
- ansible - ansible中的多个OR条件
- javascript - 如何显示最少输入 2 个字符的 Javascript 过滤器结果?
- angular - 找不到名称“列表”?(Ionic - Angular) 使用 ViewChild 时
- linux - 将docker容器内的进程绑定到linux中的特定网络接口
- excel - 如何使用应用程序将我的 Firebase 数据导出到 Excel 工作表中?