iframe身体移除空间

Joh*_*ohn 3 html iframe styles margin width

我的iframe是一种风格style="width:100%",它几乎覆盖了页面宽度.但它在左侧和右侧留下了一小部分.所以我添加body { margin:0px; }了删除空间.

它有效,但问题是删除边距<body>会影响其他内容,例如<p>内部的段落<body>.

有没有办法消除保证金只为<iframe>

码:

<!DOCTYPE html>
<html>
<body>
<p> hello </p>
<iframe src="http://www.weather.com" style="width:100%; height:95%; margin:0px"></iframe>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

Koe*_*err 6

你应该做一些像:

body{margin:0} // remove body margin

iframe{margin:0;width:100%}//remove iframe margin

p,div{margin:10px} //append margin to p and other tags
Run Code Online (Sandbox Code Playgroud)

为您的案例演示:

<!DOCTYPE html>
<html>
<head>
<style>
    body{margin:0}
    iframe{margin:0;width:100%}
    p{margin:10px}
</style>
</head>
<body>
    <p> hello </p>
    <iframe src="http://www.weather.com" style="width:100%; height:95%; margin:0px"></iframe>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)