【发布时间】:2016-02-07 21:22:45
【问题描述】:
当在 HTML5 文档类型中包含完整的高度/宽度 iframe 时,底部添加了一个我似乎无法删除的边框。这会在页面中添加一个滚动条来说明边框。不幸的是,我受到以下限制:
- 需要使用 iframe
- iframe 位于占据整个屏幕的固定位置的容器内
- html 和 body 已隐藏溢出
- 需要 HTML5 doctype(删除 doctype 或切换到较旧的 doctype 将解决滚动条问题)
- 需要保持 overflow-y: auto 和 -webkit-overflow-scrolling: touch on the #container 因为 iOS 不会滚动框架,否则(或似乎无法使其滚动)。
我有一个 plunker here 也有同样的表现。从中删除 html5 文档类型表明它可以解决问题(但这不是一个可行的解决方案)。
是否有任何 CSS 或属性可以移除边框底部并移除外部(不必要的)滚动条?
html {
box-sizing: border-box;
}
*, *:before, *:after {
box-sizing: inherit;
}
html, body {
height: 100%;
margin: 0;
padding: 0;
overflow: hidden;
}
#container {
position:fixed;
top: 0;
left: 0;
height: 100%;
width: 100%;
overflow-y: auto;
-webkit-overflow-scrolling: touch;
}
#foo {
height: 100%;
width: 100%;
}
<!DOCTYPE html>
<html>
<body>
<div id="container">
<iframe id="foo" frameborder="0" marginwidth="0" marginheight="0"
src="//www.iana.org/domains/reserved"></iframe>
</div>
</body>
</html>
【问题讨论】:
-
请在 iPhone 上查看并测试我的解决方案。我很好奇它是否成功,但对购买 iPhone 并不那么好奇。 :P
-
我没有费心测试,因为在桌面浏览器中查看时出现了两个滚动条。