Skip to content
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

Usage inside CSS #563

Open
hybridherbst opened this issue May 25, 2023 · 6 comments
Open

Usage inside CSS #563

hybridherbst opened this issue May 25, 2023 · 6 comments

Comments

@hybridherbst
Copy link

hybridherbst commented May 25, 2023

When using vue, svelte, ... or other frameworks, often images are part of styles:

<style>
.rice-drum {
    background-image: url(../components/static/Rice_Drum.jpg?format=webp);
}
</style>

vite resolves and bundles these images properly, but it seems imagetools doesn't see them - they stay in the source format and are not transformed.

Is this expected?

@dsfx3d
Copy link

dsfx3d commented Jul 19, 2023

+1

@Abilovv599
Copy link

Has anyone found a solution to this problem?

@RaymondSalim
Copy link

@Abilov599
As a workaround;

  1. Set parent container to display: relative;
  2. Create the picture element inside parent container, and set display: absolute; left: 0; top: 0; height: 100%; width: 100%

@benmccann
Copy link
Collaborator

This would need support in Vite: vitejs/vite#14686

@benmccann
Copy link
Collaborator

benmccann commented Oct 27, 2023

I just learned about image-set in CSS which may be useful here as well

Other interesting info here: https://web.dev/articles/responsive-images#images_in_css

@nosovk
Copy link

nosovk commented Feb 9, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants