如何设置iframe以填充页面宽度?

How to set iframe to fill width of page?

我想要以下这些使用 iframe 嵌入的元素来填充页面的宽度。现在,是否可以在使用 iframe 的情况下填充宽度​​,或者因为我正在使用 iframe,是不是最接近页眉、导航和页脚可以触及的边缘?

来自 html:

       <header>
            <iframe src="header.html" frameborder="0" width="100%" height="270"></iframe>
        </header>
<div id="wrap">
            <iframe src="nav.html" frameborder="0" width="100%" height="150"></iframe>

            <iframe src="footer.html" frameborder="0" width="100%" height="100"></iframe>
        </div>

来自css:

header {
    background-color: #fff;
    margin-bottom: -2%;
}
nav {
    background-color: #2c3e2c;
    overflow: auto;
}
nav a {
    color: #fff;
    font: 24px Tajawal, "Times New Roman", Arial, sans-serif;
    text-decoration: none;
    text-shadow: 2px 2px 3px #4e4337;
    text-transform: uppercase;
}

footer {
    background-color: #2c3e2c;
    color: #fff;
    font: 22px Tajawal, "Times New Roman", Arial, sans-serif;
    padding: 1% 0 1% 0;
    text-align: center;
}

问题实际上并不是因为您使用了 iframe,而是因为浏览器在其页面上自动添加了 8px of margin。要更正此问题(允许您的元素到达页面的绝对边缘),您需要设置以下内容:

body {
  margin: 0;
}