Tailwind css backround image is not working in NextJS13
Unanswered
Santhosh Prabhakaran posted this in #help-forum
I'm trying to create an background image in tailwind theme and use it in the component.
The theme looks like,
And I want to use the artists-pattern in my component like this,
But I'm getting this error,
The theme looks like,
/** @type {import('tailwindcss').Config} */
module.exports = {
content: [
"./pages/**/*.{js,ts,jsx,tsx,mdx}",
"./components/**/*.{js,ts,jsx,tsx,mdx}",
"./app/**/*.{js,ts,jsx,tsx,mdx}",
],
theme: {
fontFamily: {
shiseido: ["var(--font-ShiseidoGinza)", "sans-serif"],
headingExtRegular: ["var(--font-ShiseidoGinzaExtRegular)", "sans-serif"],
headingExtBold: ["var(--font-ShiseidoGinzaExtBold)", "sans-serif"],
},
extend: {
colors: {
primary: "#D6001C",
greyLight: "#787878",
greyDark: "#343434",
},
backgroundImage: {
"artists-pattern": "url('./app/assets/artists-gradient.png')",
},
},
},
plugins: [],
};And I want to use the artists-pattern in my component like this,
<div className="w-full h-[90vh] relative flex bg-artists-pattern">
{artists.map((artist) => {
return <div className="" key={artist.id}></div>;
})}
</div>But I'm getting this error,
9 Replies
Cape horse mackerel
I believe there's an issue with path to the image, try:
- backgroundImage: { "artists-pattern": "url('./app/assets/artists-gradient.png')"},
+ backgroundImage: { "artists-pattern": "url('/app/assets/artists-gradient.png')"},Cape horse mackerel
and if you don't want to extend your theme in the
`<div className="bg-[url('path/to/the/image')]" />
tailwind.config.js you could do `<div className="bg-[url('path/to/the/image')]" />
@Cape horse mackerel and if you don't want to extend your theme in the `tailwind.config.js` you could do
`<div className="bg-[url('path/to/the/image')]" />
When I try this, It's not showing me any suggestion regarding the path
Is it normal in this or what ?
Cape horse mackerel
how does your structure look like?
where is
where is
tailwind.config.js located?Cape horse mackerel
yeah, don't know why you're not getting any suggestion but it should work
The background image is only working in the page.jsx file which is the home page.
In other components, it's not working and throwing the error as above