调整背景图像以适应浏览器窗口 JavaScript/HTML/CSS/JQuery
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12865048/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Size Background Image to fit browser window JavaScript/HTML/CSS/JQuery
提问by atomikpanda
How can I set the background image to fit the exact size of the browser's window. I am familiar with JavaScript/HTML/CSS/JQuery so any language will work for me.
如何设置背景图像以适合浏览器窗口的确切大小。我熟悉 JavaScript/HTML/CSS/JQuery,所以任何语言都适合我。
采纳答案by atomikpanda
Thanks to @Nelson 's comment I have found my answer here: http://css-tricks.com/perfect-full-page-background-image/
感谢@Nelson 的评论,我在这里找到了答案:http://css-tricks.com/perfect-full-page-background-image/
回答by Tony Wu
Try this:
试试这个:
<img src="images/BG.jpg"
style="width:100%;height:100%;position:absolute;top:0;left:0;z-index:-5000;">
http://thewebthought.blogspot.com/2010/10/css-making-background-image-fit-any.html
http://thewebthought.blogspot.com/2010/10/css-making-background-image-fit-any.html
回答by Tony Wu
HTML & CSS:
HTML 和 CSS:
<html>
<head>
<title>bg</title>
<style>
.bg {
background: url(yourimage);
display: block;
position: absolute;
width: 100%;
height: 100%;
}
</style>
</head>
<body>
<div class="bg"></div>
</body>
</html>
回答by Ben Harrison
I've used the Backstretch jQuery plugin for this before.
我之前为此使用过 Backstretch jQuery 插件。