我的页面上有粘性元素。它按我的意愿工作。但是在我将页面放入 iframe 之后,所有粘性元素都变成静态的。
试图用 overflow: unset;
改变每个父 div,(甚至 iframe 和 upper)它没有帮助。
#accessBar {
height: 70px;
z-index: 100;
background: #e8eeff;
position: sticky;
width: calc(100% - -40px);
bottom: -1px;
margin-left: -30px;
}
最佳答案
IFrame
的样式应在 IFrame
本身内。
请注意,Sticky
规则将应用于 IFrame
<!DOCTYPE html>
<html>
<body>
<style>
iframe { height:200px; border: 0; }
</style>
<p>Your Page with Some Content...</p>
<iframe srcdoc="<!DOCTYPE html><html><body><div id='accessBar'>AccessBar</div>Long Document Ahead:<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>End of Long Document<style>html, body{ min-height:100%;position:relative} #accessBar {
background: #e8eeff;
position: -webkit-sticky; /* Safari */
position: sticky;
top: 0;
height: 20px;
}</style></body></html>"></iframe>
</body>
</html>
附言
我使用了内联 IFrame
,因此我不必在某处创建页面来托管它。
关于html - 为什么我的工作粘性 div 在 <iframe> 中不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56151273/