正如意见,如果你想要一个形象总是利用一切可以利用的高度和宽度所提到的,那么你就必须决定:是否希望图像保持宽高比 - 然后它必须被裁剪,或者您是否希望图像改变宽高比,在这种情况下它会拉伸。
下面是每个选项的例子:
没有拉伸 - 将作物
html {
background: url(http://www.olejarz.com/arted/perspective/images/intro.gif) no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
jsfiddle
拉伸 - 不裁剪
div {
background-image:url(http://www.olejarz.com/arted/perspective/images/intro.gif);
/*
* Width & Height can be percetages only when the parent
* element has explicitly declared dimensions.
*/
height:200px;
width:500px;
-moz-background-size:100% 100%;
-webkit-background-size:100% 100%;
background-size:100% 100%;
}
jsfiddle
而且还有第三个选择,你可能会不喜欢,这是包含图像,所以:
没有拉伸,不裁剪 - 不填充X/Y
html {
background: url(http://www.olejarz.com/arted/perspective/images/intro.gif) no-repeat center center fixed;
-webkit-background-size: contain;
-moz-background-size: contain;
-o-background-size: contain;
background-size: contain;
}
jsfiddle
提供jsfiddle –
我该怎么办?对不起,我在这里是新的 –
这在技术上是不可能的,所以在某些地方我们无法看到有限的信息。我的建议是使用CSS背景图像属性。你可以在这里看到一个很好的教程https://css-tricks.com/perfect-full-page-background-image/ – asimovwasright