<身体GT;宽度&高度 [英] <body> width & height
问题描述
我有一个背景图片在body标签后的div中重复。
我给了body和div 100%的宽度和高度,因为即使没有足够的内容显示我希望该图像显示在整个浏览器中。
如果页面上没有滚动条,如果有很多内容显示,我需要向下滚动背景图片,然后再显示为白色,则此功能可用。
任何帮助?
background-attachment:fixed;
background-attachment:fixed
会将您的背景保持在固定位置,以便在向下滚动时背景不会消失。
更新:
在您的情况下,背景不是附加到 当前文档结构: 为此建议的CSS: 将背景(图片)属性移至 CSS: I have a background image repeating in a div after the body tag.
I gave both body and div a width and height of 100% because even if there is not enough content to show I want that image to show on the entire browser. And this works if there is not scrollbars on the page, if there is many content showing and I need to scroll down the background image gets broken and after that is white. Any help? In your case, the background is not attached to Current document structure: Suggested CSS for this:
Move the background (image) property to the CSS:
这篇关于<身体GT;宽度&高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!< body>
,但是有两个嵌套子元素。我提出了两种可能的解决方案:方法1:不改变HTML
< body>
< div id =mainbg>
< div id =bg>
html,body {margin:0; padding:0; } / *包含在答案中,因为它很重要* /
#mainbg {
height:100%;
溢出:auto;
}
#bg {
min-height:100%;
}
方法2:建议的解决方案:
< body>
元素,并移除< div id =mainbg> ;
。
< body>
< div id =bg>
html,body {margin:0; padding:0; }
body {
background:url(../ images / main-bg-pat.png)0 0;
}
#bg {
min-height:100%;
}
background-attachment: fixed;
background-attachment:fixed
will keep your background at a fixed position, so that the background does not disappear when you scroll down.Update:
<body>
, but two nested child elements. I propose two possible solutions:Method 1: Without changing HTML
<body>
<div id="mainbg">
<div id="bg">
html, body { margin:0;padding:0; } /*Included in answer, because it's important*/
#mainbg {
height: 100%;
overflow: auto;
}
#bg {
min-height: 100%;
}
Method 2: Recommended solution:
<body>
element, and remove <div id="mainbg">
.<body>
<div id="bg">
html, body { margin:0;padding:0; }
body {
background: url(../images/main-bg-pat.png) 0 0;
}
#bg {
min-height: 100%;
}