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种不同的移动设备)中,关闭按钮被视为一个固定元素,它从不“粘”到视口的顶部(除了一个运行较旧Chrome版本的移动设备外,在那里它工作正常,但因此不能单击范围)。
click here