Html 如何在iframe中添加滚动条

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18355060/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 12:25:36  来源:igfitidea点击:

How to add scrollbars in iframe

htmliframe

提问by bsm

I want to add scrollbars in my iframe. Below is my code.

我想在 iframe 中添加滚动条。下面是我的代码。

<iframe src="http://www.w3schools.com"  width="1349px" height="100%" scrolling="auto">

</iframe>

I am writing this in Drupal 7. Problem is it doesn't show iframe with scrollbars and border. Earlier I simply set the source without width and height and scrolling options and it showed iframe with scrollbars but after adding width and height,it disappeared.

我在 Drupal 7 中写这个。问题是它没有显示带有滚动条和边框的 iframe。早些时候,我只是简单地设置了没有宽度和高度以及滚动选项的源,它显示了带有滚动条的 iframe,但在添加宽度和高度后,它消失了。

Thanks

谢谢

回答by insertusernamehere

scrolling="yes"and also frameborderaren't valid HTML5 attributes anymore. They can't be found in the list of allowed attributes, see: W3C: 4.7.6. The iframe elementor MDN: <iframe>.

scrolling="yes"并且也frameborder不再是有效的 HTML5 属性。在允许的属性列表中找不到它们,请参阅:W3C:4.7.6。iframe 元素MDN: <iframe>

Use CSS instead:

改用 CSS:

iframe {
    overflow: scroll;
    width: 1349px;
    height: 100%;
    border: 1px solid black;
}

But actually all browsers show the scrollbars right away if needed.

但实际上,如果需要,所有浏览器都会立即显示滚动条。

Demo

演示

Try before buy

先试后买

回答by Rajendra_Prasad

you were missing scrolling="yes" in your code try the following code

您在代码中缺少 scrolling="yes" 尝试以下代码

<iframe src="http://www.w3schools.com"  width="1349px" height="100%" scrolling="yes">
</iframe>

回答by DrSatan1

Change the scrollingattribute to

scrolling属性更改为

scrolling="yes"

回答by Leo T Abraham

Change scrolling="auto" to scrolling="yes"and add frameborder="1"

将 scrolling="auto" 更改为scrolling="yes"并添加frameborder="1"

Try the style:

试试风格:

iframe {
   border: 1px solid #000 !important;
   overflow: scroll !important;
}

回答by Ctrl_Null

This is not an issue with Firefox, ie, or edge.

这不是 Firefox,即,或边缘的问题。

The way i solved my particular issue is removing a class's overflow: auto and replacing it with the following on the parent of (in my current case) a table

我解决我的特定问题的方法是删除一个类的溢出:自动并将其替换为(在我当前的情况下)表的父级上的以下内容

class {
 overflow-y: scroll !important;
}