[英]Trying to stretch background to 100% height
I am trying to create a full page div (with 100% width & height). 我正在尝试创建一个整页的div(宽度和高度为100%)。 But in firefox it is not stretching fully.
但是在Firefox中,它并没有完全伸展。 Here's my code:-
这是我的代码:-
div{
background:url('image.jpg')no-repeat fixed;
background-size:cover;
}
I've tried a lot,but I don't know what's wrong. 我已经尝试了很多,但是我不知道怎么了。
Actually there's nothing wrong with your CSS as such, but in order for it to work properly you need to(unfortunately) add browser prefix 实际上,您的CSS本身没有任何问题,但是为了使其正常工作,您需要(不幸地)添加浏览器前缀
try adding 尝试添加
div{
background:url('image.jpg')no-repeat fixed;
background-size:cover;
-moz-background-size:cover;
}
Be sure you set the height of html, body
. 确保设置
html, body
的高度html, body
。
By default, the html
and body
elements do not take up the entire height of the window. 默认情况下,
html
和body
元素不占据窗口的整个高度。 You have to explicitly set the height of html, body
to force them to span the entire height of the window. 您必须显式设置
html, body
的高度html, body
以强制它们跨越窗口的整个高度。
html, body {
height:100%;
}
By forcing the html, body
to take up the entire height of the window and then placing the div { width:100%; height:100%; }
通过强制
html, body
占据窗口的整个高度,然后放置div { width:100%; height:100%; }
div { width:100%; height:100%; }
div { width:100%; height:100%; }
as a child of the body
element you can ensure that the div
will stretch to 100% of the window's width and height. div { width:100%; height:100%; }
作为body
元素的子元素,您可以确保div
可以拉伸到窗口宽度和高度的100%。
Here's an example: http://jsfiddle.net/ewF8M/ 这是一个示例: http : //jsfiddle.net/ewF8M/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.