-
Notifications
You must be signed in to change notification settings - Fork 91
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
webp for background-image #52
Comments
Hi @pabloow Unfortunately, it is not possible with pure CSS. body.webp .mydiv {
background-image: url('./images/my-image.jpg?webp');
}
body:not(.webp) .mydiv {
background-image: url('./images/my-image.jpg');
} Examples are from https://stackoverflow.com/questions/47607201/webp-image-fall-back and https://css-tricks.com/using-webp-images/ In react, you could also have a helper function and then choose the correct classname: import { supportsWebp } from './helpers'
export default () => (
<div className={supportsWebp() ? 'webp-bg' : 'fallback-bg'}>
...
</div>
); I hope that this helps you in this topic :) |
@cyrilwanner thank you :) |
How can I achieve something similar to:
'<source srcSet={require('./images/my-image.jpg?webp')} type="image/webp" /><source srcSet={require('./images/my-image.jpg')} type="image/jpeg" /><img src={require('./images/my-image.jpg')} /> '
for a background-image? Is it currently possible?
The text was updated successfully, but these errors were encountered: