<身体GT;宽度&高度 [英] <body> width & height

查看:100
本文介绍了<身体GT;宽度&高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个背景图片在body标签后的div中重复。
我给了body和div 100%的宽度和高度,因为即使没有足够的内容显示我希望该图像显示在整个浏览器中。



如果页面上没有滚动条,如果有很多内容显示,我需要向下滚动背景图片,然后再显示为白色,则此功能可用。



任何帮助?

解决方案

  background-attachment:fixed; 

background-attachment:fixed 会将您的背景保持在固定位置,以便在向下滚动时背景不会消失。

更新:



在您的情况下,背景不是附加到< body> ,但是有两个嵌套子元素。我提出了两种可能的解决方案:方法1:不改变HTML

当前文档结构:

 < body> 
< div id =mainbg>
< div id =bg>

为此建议的CSS:

  html,body {margin:0; padding:0; } / *包含在答案中,因为它很重要* / 
#mainbg {
height:100%;
溢出:auto;
}
#bg {
min-height:100%;
}



方法2:建议的解决方案:



将背景(图片)属性移至< body> 元素,并移除< div id =mainbg> ;

 < body> 
< div id =bg>

CSS:

  html,body {margin:0; padding:0; } 
body {
background:url(../ images / main-bg-pat.png)0 0;
}
#bg {
min-height:100%;
}


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?

解决方案

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:

In your case, the background is not attached to <body>, but two nested child elements. I propose two possible solutions:

Method 1: Without changing HTML

Current document structure:

<body>
    <div id="mainbg">
        <div id="bg">

Suggested CSS for this:

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:

Move the background (image) property to the <body> element, and remove <div id="mainbg">.

<body>
    <div id="bg">

CSS:

html, body { margin:0;padding:0; }
body {
    background: url(../images/main-bg-pat.png) 0 0;
}
#bg {
    min-height: 100%;
}

这篇关于&LT;身体GT;宽度&amp;高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆