我正在编写一个包含 3 个宽图像的网站,这些图像需要始终具有 100% 的宽度。我正在使用媒体查询,并且我不想为每个图像制作 3 个以上的副本来使它们适合。
这是我想要的图像 CSS:
#artwork1 {
width: 1500px;
height:500px;
background-image: url(../img/menupic_1.png);
background-repeat:no-repeat;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
}
这里是 jsFiddle 链接:http://jsfiddle.net/RtPEA/。该链接仅包含需要调整大小的背景的三个
<div>
。
我在很多网站上都使用过
background-size:cover;
,但在 Firefox 中,它似乎不适用于这个网站。
我也尝试过各种 jQuery 插件。虽然我确实发现一些取得了一些成功,但它们不适用于 iOS。
您需要在前缀版本后添加
background-size
:
#artwork1 {
width: 1500px;
height:500px;
background-image: url(../img/menupic_1.png);
background-repeat:no-repeat;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
-moz-background-size
仅在 Firefox 3.6 中受支持,其他前缀版本不保证继续存在。
前缀版本不是必需的。
#artwork1 {
width: 1500px;
height:500px;
background-image: url(../img/menupic_1.png);
background-repeat:no-repeat;
backgroud-size: cover;
}
如果您还在文档头中包含元视口元素,这在 Firefox 中也适用
<meta name="viewport" content="width=device-width, initial-scale=1.0">