CSS iFrame 和“最大高度”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4671089/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 23:27:07  来源:igfitidea点击:

iFrame and "max-height"

iframecss

提问by Mikey1980

Any ideas for using max-heighton a borderless/scrolless iFrame so if it ends up being too tall the browser doesn't render a giant black area to fill in the rest of the iFrame?

max-height在无边框/无滚动 iFrame 上使用的任何想法,因此如果它最终太高,浏览器不会呈现巨大的黑色区域来填充 iFrame 的其余部分?

I've tried setting height="100%"and max-height="xx"but that doesn't seem to work.

我试过设置height="100%"max-height="xx"但这似乎不起作用。

Many Thanks!

非常感谢!

回答by David says reinstate Monica

Your use of height="100%", using the =operator, suggests you're trying to use in-line attributes. This canwork, but usually works better with absolute measurements (so 700pxrather than a percentage). max-heightisn't a valid attribute, so far as I'm aware, of any element exceptin stylesheets, so I'd suggest that you use CSS:

您使用height="100%", 使用=运算符,表明您正在尝试使用内联属性。这可以工作,但通常在绝对测量时效果更好(700px而不是百分比)。max-height据我所知,除了样式表之外,它不是任何元素的有效属性,因此我建议您使用 CSS:

iframe {
    min-height: 200px; /* or whatever */
    max-height: 500px; /* or whatever */
}

You can, if you must, also use in-line styles, which would yield <iframe src="..." style="min-height: 200px; max-height: 500px;">

如果必须,您也可以使用内联样式,这将产生 <iframe src="..." style="min-height: 200px; max-height: 500px;">

Also, while you canuse percentages, to give max-height: 80%, this does seem to require that the parent element has a defined heightof its own (I'm not sure if it's allbrowsers, or just one or two, but either way it seems a reasonable expectation in order that the browser can work out what 80% actually is).

此外,虽然您可以使用百分比来表示max-height: 80%,但这似乎要求父元素有height自己的定义(我不确定它是所有浏览器,还是一两个,但无论哪种方式似乎都是合理的期望浏览器可以计算出 80% 的实际)。