使用css调整html标记背景图像的大小以随屏幕缩放

使用css调整html标记背景图像的大小以随屏幕缩放,html,css,image,Html,Css,Image,我在html css样式表中有一个全屏显示的图像: html { background-image: url('../images/htmlbackground.png') ; background-repeat: none; width: 100%; } 主体宽度设置为70%。主体的CSS代码为: body { width: 70%; margin: 0 auto 2em; font: 100% Georgia, "Times New Roma

我在html css样式表中有一个全屏显示的图像:

html {
    background-image: url('../images/htmlbackground.png') ;
    background-repeat: none;
    width: 100%;
}
主体宽度设置为70%。主体的CSS代码为:

body {
    width: 70%;
    margin: 0 auto 2em;
    font: 100% Georgia, "Times New Roman", Times, serif;
    color: #000000
}
正文的标题部分是正文的全宽,并覆盖背景图像。文档的主体包含两列:一列包含文本,另一列包含幻灯片


我遇到的问题是,如果我在浏览器窗口中“放大”,第1列和第2列部分会浮动到背景图像中,看起来一点也不好。是否可以在用户滚动时调整html背景图像的大小,以便正文和html图像保持相对位置?关于如何实现预期结果,还有其他建议吗?我看到的帖子似乎处理的是标签中的图像,而不是标签。

尝试使用
背景大小
属性 拉伸背景图像以完全覆盖内容区域:

html {
    background-image: url('../images/htmlbackground.png') ;
    background-repeat: none;
    width: 100%;
    background-size: 100% 100%;
}

如果我正确理解了你的问题,CSS技巧有一个很好的教程。如果您想要纯CSS方式,请使用以下方法:

html {
  background: url('../images/htmlbackground.png') center center no-repeat fixed;
  background-size: cover;
}
请确保使用浏览器前缀,以确保它可以跨所有平台工作