LoginSignup
0
0

More than 1 year has passed since last update.

Reactで言うところのbootstrapはTailwindCss

Last updated at Posted at 2022-09-25

まずはお決まりの

npx create-react-app sample-react-tailwind
cd sample-react-tailwind

ライブラリのインストール

npm install -D tailwindcss postcss autoprefixer
npx tailwindcss init -p

上記でtailwind.config.js と postcss.config.jsを作成する。
フォルダ内に
tailwind.config.jsと postcee.config.jsができる

tailwind.config.jsの「content」を以下のように修正。Tailwind CSSを反映させたいファイルを指定する。

@type {import('tailwindcss').Config} */
module.exports = {
  content: [
    "./src/**/*.{js,jsx,ts,tsx}",
  ],
  theme: {
    extend: {},
  },
  plugins: [],
}

画面に読み込んでいる./src/index.cssファイルに、以下の記述を追記する。

@tailwind base;
@tailwind components;
@tailwind utilities;
import logo from './logo.svg';
import './App.css';

function App() {
  return (
    <div className="border border-gray-400 rounded-2xl p-2 m-2 flex justify-around items-center">
      <h1 className="text-3xl font-bold underline">
        Hello Tailwind CSS!
      </h1>
      <p className="m-0 text-gray-400">Tailwind CSSです</p>
      <button className="bg-gray-300 border-0 p-2 rounded-md hover:bg-gray-400 hover:text-white">ボタン</button>
    </div>
  );
}

export default App;

こんな感じで使えるよ.
下記は参考サイト。コンポーネントのまとめ

追記
npm run startする。npm startでは駄目

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0