本页还没有译文
本页 16 段还没译成日本語,下面显示的是英文原文。How to install Tailwind CSS v3 in your Next.js application
还没翻译译自英文(nextjs.org)本页 16 段都还没译
This guide will walk you through how to install Tailwind CSS v3 in your Next.js application.
Good to know
For the latest Tailwind 4 setup, see the Tailwind CSS setup instructions.
Installing Tailwind v3
Install Tailwind CSS and its peer dependencies, then run the init command to generate both tailwind.config.js and postcss.config.js files:
pnpm add -D tailwindcss@^3 postcss autoprefixer
npx tailwindcss init -pnpm install -D tailwindcss@^3 postcss autoprefixer
npx tailwindcss init -pyarn add -D tailwindcss@^3 postcss autoprefixer
npx tailwindcss init -pbun add -D tailwindcss@^3 postcss autoprefixer
bunx tailwindcss init -pConfiguring Tailwind v3
Configure your template paths in your tailwind.config.js file:
tailwind.config.js
/** @type {import('tailwindcss').Config} */
module.exports = {
content: [
'./app/**/*.{js,ts,jsx,tsx,mdx}',
'./pages/**/*.{js,ts,jsx,tsx,mdx}',
'./components/**/*.{js,ts,jsx,tsx,mdx}',
],
theme: {
extend: {},
},
plugins: [],
}Add the Tailwind directives to your global CSS file:
app/globals.css
@tailwind base;
@tailwind components;
@tailwind utilities;Import the CSS file in your root layout:
app/layout.tsx
import './globals.css'
export default function RootLayout({
children,
}: {
children: React.ReactNode
}) {
return (
<html lang="en">
<body>{children}</body>
</html>
)
}app/layout.js
import './globals.css'
export default function RootLayout({ children }) {
return (
<html lang="en">
<body>{children}</body>
</html>
)
}Using classes
After installing Tailwind CSS and adding the global styles, you can use Tailwind's utility classes in your application.
app/page.tsx
export default function Page() {
return <h1 className="text-3xl font-bold underline">Hello, Next.js!</h1>
}app/page.js
export default function Page() {
return <h1 className="text-3xl font-bold underline">Hello, Next.js!</h1>
}Usage with Turbopack
As of Next.js 13.1, Tailwind CSS and PostCSS are supported with Turbopack.
AI 翻译查看英文原文