Comments (2)
Hey!
In the VideoOverlay.tsx
file you have the following code:
<div
className={`preview bg-[url('${previewSrc}')] absolute inset-0 z-[1] bg-cover bg-no-repeat`}
onClick={() => {
playPauseVideo()
}}
></div>
Tailwind CSS itself doesn't execute your code, so it generates the bg-[url(…)]
as-is (more info: https://tailwindcss.com/docs/content-configuration#dynamic-class-names). This means that it generates the following CSS:
.bg-\[url\(\'\$\{previewSrc\}\'\)\] {
background-image: url('${previewSrc}');
}
Once that is generated, Next.js does optimizations for (background) images. In this case, it will look for url('${previewSrc}')
which doesn't exist on disk. Note: this would also happen without Tailwind CSS if you used that literal string in the background-image
.
To solve your issue, I would recommend to use a CSS variable instead:
<div
- className={`preview bg-[url('${previewSrc}')] absolute inset-0 z-[1] bg-cover bg-no-repeat`}
+ className={`preview bg-[url:var(--preview-src))] absolute inset-0 z-[1] bg-cover bg-no-repeat`}
+ style={{ '--preview-src': `url(${previewSrc})` }}
onClick={() => {
playPauseVideo()
}}
></div>
This way, Tailwind generates the following CSS for bg-[url:var(--preview-src))]
:
.bg-\[url\:var\(--preview-src\)\] {
background-image: var(--preview-src);
}
Now you can generate the --preview-src
dynamically at runtime using the style
prop.
Hope this helps!
from tailwindcss.
Object literal may only specify known properties, and ''--preview-src'' does not exist in type 'Properties<string | number, string & {}>'.typescript(2353)
index.d.ts(1982, 9): The expected type comes from property 'style' which is declared here on type 'DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>'
It doen't work in way you described
It work like this
style={{ backgroundImage: `var(--preview-src, url(${previewSrc}))` }}
from tailwindcss.
Related Issues (20)
- [v4] Chrome ~v103 chokes on comma in .bg-gradient-* Utility HOT 1
- PostCSS plugin not processing changes outside base directory HOT 3
- Tailwind does not delete unused css
- Cannot transition between outer and inner shadows
- Border is being overwritten despite appearing after the original border class
- tailwind-cli casually emits to `stderr` HOT 2
- [v4] Publish @tailwindcss/postcss as ESM HOT 2
- [v4] Sourcemaps not enabled in postcss plugin HOT 2
- bg-opacity doesn't work on dark mode
- ```content.transform``` doesn't work in next.js HOT 1
- [Prettier Plugin] Handle two more plugins HOT 3
- not working in docker HOT 3
- other postcss plugins do not work with tailwindcss HOT 1
- `<alpha-value>` is not recognized on reuse HOT 2
- Vulnerable Dependency - micromatch HOT 3
- v4: tailwind.default is not a function when running with Angular 17 and esbuild
- Classes generation error using symlink HOT 1
- bradlc.vscode-tailwindcss-0.10.5 makes CPU go Brrrrrrrr HOT 2
- [v3] Double quotes break arbitrary variants HOT 2
- `dark:` does not work with `@apply` in v3.4.3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tailwindcss.