无法在IE中删除可怕的iframe水平滚动条?

时间:2020-03-05 18:54:38  来源:igfitidea点击:

我有一个iframe。内容比我设置的宽度要宽,因此iframe会获得水平滚动条。我无法增加iframe的宽度,所以我只想删除滚动条。我尝试将scroll属性设置为" no",但这会杀死两个滚动条,而我想要垂直滚动条。我尝试将overflow-x设置为" hidden",这杀死了ff中的水平滚动条,但没有杀死IE中的水平滚动条。为我难过。

解决方案

回答

我们可以尝试将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>的属性,而是它包含的页面的属性。尝试将" overflow-x:hidden"放在内页的" <html>"元素上。

回答

<iframe style="overflow:hidden;" src="about:blank"/>

应该在IE中工作。 IE6在支持overflow-x和overflow-y时遇到问题。

要注意的另一件事是,只有在camelCase中设置" frameborder"属性,才能删除IE在iframe上的边框。

<iframe frameBorder="0" style="overflow:hidden;" src="about:blank"/>

如果我们可以使用CSS正确设置样式,但它在IE中不起作用,那就太好了。

回答

scrolling="yes"  horizontalscrolling="no" verticalscrolling="yes"

将其放在iFrame标签中。

我们无需费心尝试在CSS中设置其格式。

回答

所有这些解决方案都对我不起作用或者不令人满意。使用可滚动的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%。