CSS:将图像拉伸到 100% 宽度
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5362750/
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
CSS: Stretching image to 100% width
提问by nimrod
Hi all I am trying to strech the background of my side to fit the width. I only found big workarounds in the internet. Is there not one single command for this?
大家好,我正在尝试拉伸我身边的背景以适应宽度。我只在互联网上找到了大的解决方法。难道没有一个命令可以做到这一点吗?
body {
background-image: url(money.jpg);
}
Thanks for the answers. Doonot
感谢您的回答。杜诺特
回答by sgokhales
Use background-sizelike the one used below,
使用如下所示的背景尺寸,
body {
background-image: url(money.jpg) no-repeat;
background-size: 100%;
}
Some useful links :
一些有用的链接:
回答by Keltex
If you have a CSS3 browser you can use background-size
(read more about background-size):
如果你有一个 CSS3 浏览器,你可以使用background-size
(阅读更多关于 background-size):
body {
background-image: url(money.jpg);
background-size: 100%;
}
Unfortunately this won't work in IE 6-8. IE 9, Firefox, Chrome, Safari it will work fine.
不幸的是,这在 IE 6-8 中不起作用。IE 9、Firefox、Chrome、Safari 都可以正常工作。