About this Article
This is an article about using taillwind in react.
What is Tailwind?
Tailwind is a CSS flamework.
As show below, you can add class to element,and adopt style.
https://tailwindcss.com/
How to install
installing package
npm install -D tailwindcss@npm:@tailwindcss/postcss7-compat @tailwindcss/postcss7-compat postcss@^7 autoprefixer@^9
npm install postcss-cli autoprefixer --save-dev
or
yarn add postcss-cli autoprefixer --save-dev
create styles.css
Create style.css and import @tailwind property.
@tailwind base;
@tailwind components;
@tailwind utilities;
Add script command to build Tailwind in package.json.
"scripts": {
"start": "react-scripts start",
"build:tailwind":"tailwind build src/styles.css -o src/tailwind.css",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
And run below.
npm run-script build:tailwind
Then,tailwind.css will be created.
import tailwind.css
import './tailwind.css';
Check importing.
If you write the following,you can confirm tailwind.css
import React from "react";
function App() {
return (
<div className="App">
<div class="max-w-sm rounded overflow-hidden shadow-lg">
<img
class="w-full"
src="https://source.unsplash.com/random/1600x900/"
alt="Sunset in the mountains"
></img>
<div class="px-6 py-4">
<div class="font-bold text-xl mb-2">The Coldest Sunset</div>
<p class="text-gray-700 text-base">
Lorem ipsum dolor sit amet, consectetur adipisicing elit.
Voluptatibus quia, nulla! Maiores et perferendis eaque,
exercitationem praesentium nihil.
</p>
</div>
<div class="px-6 py-4">
<span class="inline-block bg-gray-200 rounded-full px-3 py-1 text-sm font-semibold text-gray-700 mr-2">
#photography
</span>
<span class="inline-block bg-gray-200 rounded-full px-3 py-1 text-sm font-semibold text-gray-700 mr-2">
#travel
</span>
<span class="inline-block bg-gray-200 rounded-full px-3 py-1 text-sm font-semibold text-gray-700">
#winter
</span>
</div>
</div>
</div>
);
}
export default App;
参考記事
https://blog.logrocket.com/create-react-app-and-tailwindcss/
Top comments (0)