css - CSS 位置:sticky 表现得像固定(在 w3.css 模式中)
问题描述
我的模态粘性关闭按钮无法正常工作。即使我在我的 css 规则中指定了它top:0
,它也不会表现得像一个固定元素。-webkit-position:sticky;position:sticky;
下面你可以看到我的代码片段:
<html>
<head>
<style>
.modalclose {
position: -webkit-sticky;
position: sticky;
width: 100%;
top: 0px;
}
</style>
<link rel="stylesheet" href="./css/w3.css">
</head>
<body>
<div class="w3-modal">
<div class="w3-modal-content w3-display-container">
<div style="position:absolute;top:0;left:0;height:43px;width:100%;background-color:black;"></div>
<div onclick="javascript:void(0);" class="w3-button w3-large w3-display-topright modalclose w3-black w3-text-white">x</div>
<div class="w3-container w3-black">
<h1>LOREM IPSUM</h1>
</div>
<div class="w3-container" style="padding-bottom: 2000px">
<h5>Lorem Ipsum</h5>
</div>
</div>
</div>
</body>
</html>
在 Firefox(桌面)和 Chrome(3 种不同的移动设备)中,关闭按钮被视为固定元素,它永远不会“粘”在视口的顶部(除了 1 个运行较旧的移动设备chrome 版本,它工作正常,但因此跨度不可点击)。
我究竟做错了什么?
这是我页面上上述代码的链接:单击此处
解决方案
问题是 .w3-modal 有一个固定的位置和一个 100px 的 padding-top。它永远不会离开屏幕。它有一个 100px 的 padding-top。
您的 .modalclose 已经很粘并且工作正常。
尝试删除 .w3-modal 类的固定位置。如果您希望固定模态,则可以从中删除 padding-top: 100px ,以便 .modalclose 可以到达屏幕顶部。
推荐阅读
- azure-cosmosdb - Cosmos Db 跨分区事务
- hibernate - Hibernate 一对多映射返回 null
- r - ggplot2 png文件没有背景
- c - 在 C 中使用 fscanf 时打印输出出错
- c++ - Window Framework Win32 API 中的异常
- python - 使用 MongoDB 为我的命令创建冷却时间
- javascript - 如何使用 appscript 直接从 Html 页面更新电子表格单元格值
- javascript - 如何保持 OrbitControl 相机位置
- python - 无法从时间戳转换为日期
- php - Wordpress 中类别基本 url 的每一页上的错误 404