html - 背景图100%固定位置问题

标签 html css background

我通过将背景图像应用到正文并保持固定位置,使我的网站背景图像拉伸(stretch)了浏览器窗口的 100% 宽度和高度。此外,我使用以下方法创建了也将保持固定的边框:http://css-tricks.com/body-border/

如您所见,它工作正常:http://br-webdesigner.com/test/

唯一的问题是,即使我在 html 元素上填充了 10 像素,但背景图像一直延伸到浏览器窗口的边缘,而不是延伸到 body 元素的边界(或绿色区域) .

似乎将 background-size 设置为 100% 会使浏览器窗口的大小变为 100%,而不是包含元素的大小。

有办法解决这个问题吗?

谢谢,

最佳答案

所以我稍微修改了你的 CSS,尝试使用这个:

html{

}

body{
 padding:30px;   
background:url(images/bg2.svg) no-repeat fixed;
background-size:100% 100%;
margin:0;
}

.site-border{
background:#352e2e;
z-index:10;
}

#top{
position:fixed;
top:0;
left:0;
width:100%;
height:10px;
}

#bottom{
position:fixed;
bottom:0;
left:0;
width:100%;
height:10px;
}

#left{
    padding:10px;
position:fixed;
left:0;
top:0;
width:10px;
height:100%;
}

#right{
    padding:10px;
position:fixed;
right:0;
top:0;
width:10px;
height:100%;
}

关于html - 背景图100%固定位置问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15868777/

相关文章:

html - 如何为所有主要浏览器禁用自动完成

javascript - 谷歌图表不会在顶部对齐

javascript - 在 PHP 循环中动态创建 jQuery listview

css - 为什么 Font-Size 和 CssClass 属性在 aspx 页面的 CheckBoxList 中不起作用?

html - 自定义列表样式 "bullet"或透明获取列表编号

html - 真或假的 v-bind 条件不起作用

html - Bootstrap : How to force form-inline in mobile?

Android - 使用 BroadcastReceiver 的服务

css - Web 标记,背景颜色设置为基础

Android:从服务检测触摸