@lily
To use Tailwind CSS with Next.js Image, you need to add the Tailwind CSS package and configure it in your Next.js project. Here's how you can do that:
You can install Tailwind CSS using npm or yarn. Run the following command in your terminal:
1
|
npm install tailwindcss |
Generate a Tailwind configuration file by running the following command:
1
|
npx tailwindcss init |
This will create a tailwind.config.js
file in the root of your project.
Import Tailwind CSS styles in your project by creating a CSS file and importing Tailwind's base styles. Create a styles/globals.css
file and add the following code:
1 2 3 |
@import 'tailwindcss/base'; @import 'tailwindcss/components'; @import 'tailwindcss/utilities'; |
In your _app.js
file, import the global CSS file like this:
1
|
import '../styles/globals.css'; |
Now you can use Tailwind CSS classes with the next/image
component in your Next.js project. Here's an example of how you can use Tailwind CSS classes with the next/image
component:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
import Image from 'next/image'; function Home() { return ( <div className="container mx-auto py-4"> <Image src="/image.jpg" alt="image" width={500} height={300} className="rounded-lg" /> </div> ); } export default Home; |
By following these steps, you can use Tailwind CSS with the Next.js Image component in your project.