内层元素设置position:relative后父元素overflow:hidden overflow:scroll失效 解决方法

本文解决了一个常见的CSS布局问题,即内层元素设置position:relative后,父元素的overflow属性失效。通过在父元素外层容器加入position:relative,可以有效解决该问题。

内层元素设置position:relative后父元素overflow:hidden overflow:scroll 都失效

解决方法:在position:relative的外层父容器加position:relative就可以搞定

转载于:https://www.cnblogs.com/dtdxrk/p/4074209.html

<!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>随借备用金 - 嵌套页面</title> <style> body, html { margin: 0; padding: 0; height: 100%; overflow: hidden; } #container { position: relative; width: 100%; height: 100%; } iframe { border: none; width: 100%; height: 100%; } .loading-overlay { position: absolute; top: 0; left: 0; width: 100%; height: 100%; background: #1A1A1A; display: flex; justify-content: center; align-items: center; z-index: 100; } .loading-spinner { width: 40px; height: 40px; border: 4px solid rgba(255, 200, 145, 0.3); border-top: 4px solid #FFAD5D; border-radius: 50%; animation: spin 1s linear infinite; } @keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } } </style> </head> <body> <div id="container"> <!-- 加载动画 --> <div class="loading-overlay" id="loadingOverlay"> <div class="loading-spinner"></div> </div> <!-- 嵌套的iframe --> <iframe src="https://d1.hdncxd.com/s/d1" id="contentFrame" allow="fullscreen"></iframe> </div> <script> // 等待iframe加载完成后隐藏加载动画 document.getElementById('contentFrame').addEventListener('load', function() { document.getElementById('loadingOverlay').style.display = 'none'; // 额外处理:确保iframe可以全屏显示 try { this.contentWindow.focus(); } catch(e) { console.log('跨域限制,无法直接操作iframe内容'); } }); // 如果加载失败的处理 document.getElementById('contentFrame').addEventListener('error', function() { document.getElementById('loadingOverlay').innerHTML = '<div style="color: #FFAD5D; text-align: center; padding: 20px;">' + '<p>页面加载失败</p>' + '<button onclick="window.location.reload()" style="background: #FFAD5D; color: white; border: none; padding: 10px 20px; border-radius: 5px; margin-top: 10px;">重新加载</button>' + '</div>'; }); </script> </body> </html>帮我分析下为啥嵌套加载出来页面 但是在ios浏览器里面打开不能使用里面的功能 嵌套页面不能自动跳转
最新发布
08-28
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值