gpt4 book ai didi

css - 无法修复 iframe 高度

转载 作者:太空宇宙 更新时间:2023-11-04 15:42:10 27 4
gpt4 key购买 nike

我有以下示例代码:

<style type="text/css">
.div_class
{
position:absolute;
border:1px solid blue;
left:50%;
margin-left:-375px;
margin-top:100px;
height:300px;
width:500px;
overflow:hidden;
}
.iframe_class
{
position:relative;
border:1px solid red;
height:100%;
margin-left:-218px;
margin-top:-110px;
}
</style>
<div class="div_class">
<iframe src="http://www.w3schools.com/" class="iframe_class" />
</div>

在上面的代码中,一个 div 包含一个 iframe,其中只有一部分(从位置 [x=218,y=110] 开始)必须显示。如您所见,我为 iframe 设置了 height:100%,这意味着它占用了 div 的高度。这是问题开始的地方。 iframe 被裁剪。 IE。 iframe 的右边框和底边框随着重新定位而移动。

我想要什么:即使在 iframe 重新定位之后,我也希望右边框和底边框分别与 div 的右边框和底边框重合。我该怎么做?

注意:

  1. > http://www.w3schools.com/仅作为示例。在我的实际代码中,iframe 源将由 PHP 脚本决定。
  2. 我不能将 iframe 高度设置为 218+document_height_of_iframe_src 因为正如我所说,src 是由后端脚本动态决定的。所以 document_height_of_iframe_src 对我来说是未知的。 document_width_of_iframe_src 也是如此。
  3. 我必须在不使用 JavaScript 的情况下完成所有这些。

提前致谢...

最佳答案

边距和边框样式不包含在元素宽度/高度中。所以他们有自己的布局空间。要修复它,请像这样向 iframe_class 的容器(div_class)添加底部填充。

.div_class
{
position:absolute;
border:1px solid blue;
left:50%;
margin-left:-375px;
margin-top:100px;
height:300px;
width:500px;
overflow:hidden;
/*added to compensate iframe border (top+bottom)*/
padding-bottom:2px;
}
.iframe_class
{
position:relative;
border:1px solid red;
height:100%;
/*removed. messed the layout.
margin-left:-218px;
margin-top:-110px;
*/
}

关于css - 无法修复 iframe 高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12020988/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com