简体   繁体   English

设置iframe的正确方法是什么?

[英]What is the proper way to style an iframe?

I started fiddling with an iframe here: 我开始在这里摆弄iframe:

http://jsfiddle.net/M68GL/3 http://jsfiddle.net/M68GL/3

<iframe id="test" width="400" src="http://www.digg.com"></iframe>

I want to get rid of the scroll bars and the strange border but can't figure out how to do it. 我想摆脱滚动条和奇怪的边框,但不知道如何去做。

According to: 根据:

https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe https://developer.mozilla.org/zh-CN/docs/Web/HTML/Element/iframe

the use of the scrolling attribute is deprecated in HTML 5. 在HTML 5中不推荐使用scrolling属性。

Also I see no attiribute for the border. 我也看不到边界有任何装饰。

Can I just give the element an id and style it using CSS? 我可以给元素一个id并使用CSS设置样式吗?

Using HTML5. 使用HTML5。

Personally, I use frameborder="0" to get rid of the border, but just using border:0 in CSS should do it too. 就个人而言,我使用frameborder="0"摆脱了边界,但是在CSS中仅使用border:0也可以做到这一点。

As for the scroll bars, you can try adding overflow:hidden , but usually it's the child document that needs to specify that on its html element. 至于滚动条,您可以尝试添加overflow:hidden ,但通常是子文档需要在其html元素上进行指定。 If you don't control the child document, then you can't stop scrolling with CSS and will need to use the deprecated attribute instead. 如果您不控制子文档,则无法停止使用CSS滚动,而需要使用不推荐使用的属性。

The answer is as expected, cross-browser incompatible as of yet. 答案是预期的,到目前为止,跨浏览器不兼容。 Nonetheless, here it is, a mixture of old and new: 但是,这里是新旧的结合:

<iframe frameborder="0" scrolling="no" seamless>

This may not validate in W3C, but your customers will not notice, nor will it affect negatively the operation of your page(s). 这可能无法在W3C中验证,但是您的客户不会注意到,也不会对您的页面操作产生负面影响。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM