我想尝试使用WebP格式的图像作为我的网页上的背景图像.但是我不确定,如果在这种情况下浏览器不支持WebP格式的CSS如何使用经典的jpg图像.我发现这个示例代码,芽不起作用
.mybackgroundimage {
background-image: url("image.jpg");
background-image: image("image.webp" format('webp'), "image.jpg");
}
Run Code Online (Sandbox Code Playgroud)
您必须使用modernizr来检测浏览器是否支持webp,然后对其应用适当的样式
.no-webp .mybackgroundimage
{
background: url('image.jpg') no-repeat;
}
.webp .mybackgroundimage
{
background: url('image.webp') no-repeat;
}
Run Code Online (Sandbox Code Playgroud)