【发布时间】:2008-09-15 21:49:59
【问题描述】:
我有一个 iframe。内容比我设置的宽度宽,所以 iframe 有一个水平滚动条。我无法增加 iframe 的宽度,所以我只想删除滚动条。我尝试将滚动属性设置为“否”,但这会杀死两个滚动条,我想要垂直滚动条。我尝试将 overflow-x 设置为“隐藏”,这会杀死 ff 中的水平滚动条,但不会在 IE 中。为我难过。
【问题讨论】:
我有一个 iframe。内容比我设置的宽度宽,所以 iframe 有一个水平滚动条。我无法增加 iframe 的宽度,所以我只想删除滚动条。我尝试将滚动属性设置为“否”,但这会杀死两个滚动条,我想要垂直滚动条。我尝试将 overflow-x 设置为“隐藏”,这会杀死 ff 中的水平滚动条,但不会在 IE 中。为我难过。
【问题讨论】:
scrolling="yes" horizontalscrolling="no" verticalscrolling="yes"
把它放在你的 iFrame 标签中。
您无需在 CSS 中尝试格式化。
【讨论】:
滚动条不是<iframe> 的属性,它是它所包含的页面的属性。尝试将overflow-x: hidden 放在内页的<html> 元素上。
【讨论】:
您可以尝试将 iframe 放入 div 中,然后使用 div 进行滚动。您可以毫无问题地控制 IE 中 div 的滚动,IE 只有 iframe 滚动确实存在问题。这是一个可以解决问题的简单示例。
<html>
<head>
<title>iframe test</title>
<style>
#aTest {
width: 120px;
height: 50px;
padding: 0;
border: inset 1px #000;
overflow: auto;
}
#aTest iframe {
width: 100px;
height: 1000px;
border: none;
}
</style>
</head>
<body>
<div id="aTest">
<iframe src="whatever.html" scrolling="no" frameborder="0"></iframe>
</div>
</body>
</html>
【讨论】:
<iframe style="overflow:hidden;" src="about:blank"/>
应该在 IE 中工作。 IE6 在支持overflow-x 和overflow-y 时存在问题。
另外需要注意的是,IE在iframe上的边框只有在camelCase中设置了“frameborder”属性才能被移除。
<iframe frameBorder="0" style="overflow:hidden;" src="about:blank"/>
如果你能用 CSS 正确地设置样式就好了,但它在 IE 中不起作用。
【讨论】:
所有这些解决方案都对我不起作用或不令人满意。使用可滚动的 DIV,您可以使水平滚动条消失,但您将始终拥有垂直滚动条。
因此,对于我可以确保控制所有 iframe 的固定高度的网站,以下解决方案非常有效。 它只是用 DIV 隐藏水平滚动条 :)
<!-- This DIV is a special hack to hide the horizontal scrollbar in IE iframes -->
<!--[if IE]>
<div id="ieIframeHorScrollbarHider" style="position:absolute; width: 768px; height: 20px; top: 850px; left: 376px; background-color: black; display: none;">
</div>
<![endif]-->
<script type="text/javascript">
if (document.getElementById("idOfIframe") != null && document.getElementById("ieIframeHorScrollbarHider") != null)
{
document.getElementById("ieIframeHorScrollbarHider").style.display = "block";
}
</script>
【讨论】:
您还可以尝试将 iframe 中包含的页面正文的宽度设置为 99%。
【讨论】: