IFrame滚动条不会出现在Chrome上

Sid*_*rth 9 iframe google-chrome scrollbar

我正在使用IFrame来展示来自其他领域的一些内容.问题是我可以使用指定的高度和宽度(我正在使用),IFrame中的内容无法完全容纳在IFrame中.因此,我需要滚动条.

我使用了以下HTML代码 -

**<iframe style = "overflow-x:scroll; overflow-y:scroll;" src =       "http://shopsocial.ly/merchant/fanpage?merchant_name=cafepress"
     height = "400" width = "500">**
Run Code Online (Sandbox Code Playgroud)

这在Firefox中运行良好.但在Chrome中,我没有在IFrame中获得任何滚动条.我已经搜索过这个问题并尝试过很多东西,但都没有解决我的问题.有人可以帮我弄这个吗?

Raf*_*shi 6

在您的 iframe 内容中添加内联:

<body style="overflow:auto;">
Run Code Online (Sandbox Code Playgroud)

或者在附加到 iframe 的 css 文件中

html, body {
   overflow:auto;
}
Run Code Online (Sandbox Code Playgroud)

当然,按照 Tom 的建议,请确保在 iframe 上使用scrolling="yes"和:style="overflow:visible;"

<iframe scrolling="yes" src="http://example.com" style="overflow:visible;"></iframe>
Run Code Online (Sandbox Code Playgroud)

如果仍然不起作用,请尝试像这样包装 iframe:

<div style="overflow:visible; height:400px;">

    <iframe scrolling="yes" src="http://example.com" style="overflow:visible; height:2000px;"></iframe>

</div>
Run Code Online (Sandbox Code Playgroud)


Tom*_*ort 4

您可以使用iframe 的滚动yes属性并将其设置为(即始终显示滚动条),而不是使用 CSS 样式:

<iframe scrolling="yes" src="http://domain.com" height="400" width="500"></iframe>
Run Code Online (Sandbox Code Playgroud)

  • 我发现了这个问题,我认为这是 Chrome 上的一个错误 - IFrame 中显示的内容的正文是用标签 &lt;body style = "overflow:hidden;"&gt; 定义的。如果删除正文中的样式元素,则 IFrame 将根据需要使用滚动条进行渲染。在 Firefox 上,不会导致此类问题。您认为这是 Chrome 的 bug 还是 HTML 需要这样编写? (12认同)