html自动删除多余的空格,html-删除多余的空白环绕iframe?

html-删除多余的空白环绕iframe?

我在页面中使用iframe,偶然发现了一个奇怪的问题。 我像这样设置iframe css

iframe {

margin: none;

padding: none;

background: blue; /* this is just to make the frames easier to see */

border: none;

}

但是,iframe周围仍然存在空白。 我在Chrome和Firefox中都对其进行了测试,并且相同。 我到处搜寻,却找不到任何东西。 该空白也不会显示在Chrome控制台中。另外,我已经有了以下CSS:

html, body {

margin: 0px;

padding: 0px;

border: 0px;

width: 100%;

height: 100%;

}

JSFiddle:这里

9个解决方案

67 votes

刚刚看到您的小提琴是您的问题,因为您使用的是display:block。这将html中的空格考虑在内。 display:inline-block因难以处理而臭名昭著,并且拥有模糊的浏览器支持。

选项1:尝试删除html中的空格有时可以解决问题。

选项2:使用不同的显示属性(例如display:block)肯定会解决问题。 实时示例:[http://jsfiddle.net/mM6AB/3/]

tw16 answered 2020-02-14T12:20:30Z

15 votes

当您使用嵌入式元素时,空格可能来自该元素所属的“线”(即基线下方的空间)。 解决方案是将其添加到其父元素。

line-height: 0;

Jeff Clemens answered 2020-02-14T12:20:51Z

9 votes

iframe { display:block; }

iframe是内联元素

Sergio Rodrigues answered 2020-02-14T12:21:11Z

3 votes

也许空白实际上是加载到中的文档的外边距。 尝试使用以下方式对加载的文档进行样式化(对源页面进行CSS样式化):

html, body {

border: 0px;

margin: 0px;

padding: 0px;

}

引用从stackoverflow.com这里

Tooma answered 2020-02-14T12:21:36Z

2 votes

我有同样的问题,我通过浮动框架元素解决了

iframe {

margin: none;

padding: none;

border: none;

line-height: 0;

float: left;

}

answered 2020-02-14T12:21:56Z

1 votes

没有您的html内容很难解决,但是请尝试一下:

iframe {

margin: 0px !important;

padding: 0px !important;

background: blue; /* this is just to make the frames easier to see */

border: 0px !important;

}

html, body {

margin: 0px !important;

padding: 0px !important;

border: 0px !important;

width: 100%;

height: 100%;

}

添加!important将强制样式,这是因为您的样式相互覆盖。

Marc Uberstein answered 2020-02-14T12:22:21Z

1 votes

尝试在周围使用带有overflow: hidden;的div,例如

Your browser does not support iframes.

dipankar answered 2020-02-14T12:22:41Z

0 votes

由于给出的答案都没有为我提供解决方案(在实施iFrame时,我也偶然发现了奇怪的保证金问题),因此我发现这很好用:

marginwidth和marginheight无效/官方支持的HTML5-标签,但在我的测试中它们可以正常工作...

Leander answered 2020-02-14T12:23:05Z

-2 votes

尝试html, body {margin:0px;}

Caroline Elisa answered 2020-02-14T12:23:25Z

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值