I’m trying to extend tailwind backgroundImages and no matter what I put as the image’s path it doesn’t recognize. I tried search for the answer and wasn’t able to figure out. I’m using vite in this project.
tailwind.config.css
/** @type {import('tailwindcss').Config} */
export default {
content: [
"./src/**/*.{js,jsx,ts,tsx}",
],
theme: {
extend: {
backgroundImage: {
'es': "url('/src/assets/images/es.png')",
'us': "url('/src/assets/images/us.png')",
'pt': "url('/src/assets/images/pt.png')",
}
},
},
plugins: [],
}
vite.config.js
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react-swc'
// https://vitejs.dev/config/
export default defineConfig({
plugins: [react()],
})
I tried to use vite alias to configure in some way, as well as trying multiple image paths including change the folder to public
. But neither did work.
2
Answers
save your image in src/assets and in extends create a backgroundImage cofig in tailwind.config.js like this:
so you can use it like this :
i attach some image for you.
If you have your images in your public directory, it’s best to access it as so:
/assets/images
Find more here on how to handle image paths
then you can access the class as: