HTML5:iframe没有滚动?

jav*_*web 43 iframe html5 scroll

说到HTML5,不再支持滚动属性 - 但我仍然需要删除滚动条 - 如何做到这一点?

jav*_*web 51

在HTML5中没有滚动属性,因为"其功能更好地由CSS处理",请参阅http://www.w3.org/TR/html5-diff/进行其他更改.好吧和CSS解决方案:

CSS解决方案:

HTML4 scrolling="no"是CSS的别名overflow: hidden,为此,设置大小属性width/height非常重要:

iframe.noScrolling{
  width: 250px; /*or any other size*/
  height: 300px; /*or any other size*/
  overflow: hidden;
}
Run Code Online (Sandbox Code Playgroud)

将此课程添加到您的iframe,您就完成了:

<iframe src="http://www.example.com/" class="noScrolling"></iframe>
Run Code Online (Sandbox Code Playgroud)

!重要的提示 !: overflow: hidden<iframe>未完全通过所有现代浏览器都支持,但(即使Chrome不支持它尚未)所以现在(2013),它仍然是更好地使用过渡版和使用scrolling="no",并overflow:hidden在同一时间:)

  • 为什么不`iframe [scrolling ='no'] {overflow:hidden; }`? (18认同)
  • 但是,永远不会删除iframe [scrolling ="no"];) (9认同)
  • @mattcurtis好了,因为自CSS2以来支持属性选择器 - 它也是一个解决方案:) - **但请记住**有一天会删除scrolling ="no" - 因此class更透视:) (7认同)
  • 溢出仍然对2017年的fx和chrome中的iframe没有影响 (5认同)
  • 如果可以的话,在iframe中向文档的CSS中添加`html,body {overflow:hidden }`似乎也可行. (3认同)
  • 2019年对Chrome仍然没有影响 (2认同)