我想要使用 iframe 嵌入的以下这些元素来填充页面的宽度。现在,是否可以在使用 iframe 的情况下填充宽度,或者因为我正在使用 iframe,是最接近页眉、导航和页脚可以触及的边缘吗?
<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
的 margin
。要更正此问题(允许您的元素到达页面的绝对边缘),您需要设置以下内容:
body {
margin: 0;
}
关于html - 如何设置iframe以填充页面宽度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52394602/