Html 设置CSS背景图像而不影响页面高度

Html 设置CSS背景图像而不影响页面高度,html,css,iframe,Html,Css,Iframe,我正在将页面加载到iframe中。iframe的源具有用于设置背景图像的CSS设置: body { background: url("//mydomain.com/bg.jpg") no-repeat scroll center top; } 图像的高度为1586px。它必须是所有页面的背景(大约有6页),并且不能缩放。如果页面高度小于1586px,则应裁剪背景图像 我的问题是iframe的高度总是1586px,即使页面(src=)要短得多。我试过溢出:隐藏,但没用。嗯。也许试试 bo

我正在将页面加载到iframe中。iframe的源具有用于设置背景图像的CSS设置:

body {
    background: url("//mydomain.com/bg.jpg") no-repeat scroll center top;
}
图像的高度为1586px。它必须是所有页面的背景(大约有6页),并且不能缩放。如果页面高度小于1586px,则应裁剪背景图像

我的问题是iframe的高度总是1586px,即使页面(src=)要短得多。我试过溢出:隐藏,但没用。

嗯。也许试试

body {
    display: inline-block;
    width: 100%;
    height: auto;
}

如果不起作用,请尝试选择
html,body
而不是仅选择
body

您是否尝试过背景尺寸:封面

试试这个:

body {
    background-image: url("../bg.jpg");
    background-position: center center;
    background-repeat: no-repeat;
    background-size: cover;
}

我没试过height:auto,以为它能用,但没什么区别。我用了你的3行代码和html,body。