Tailwind CSS notes by ~ Maan Patel
To setup Tailwind CSS, run these commands on your terminal:
- "npm install -D tailwindcss postcss autoprefixer" // install required packages
- "npx talwindcss init"
- "npx tailwindcss init -p"
- "npm install vite" (to run the server)
- Create a "index.html" file
- Create a css file "input.css", add it to your html and edit it with this content:
@tailwind base;
@tailwind components;
@tailwind utilities;
- Add this scipt line: "" in the tag (because to see the suggestions for classes in the html file while coding which makes your work easier)
- In your tailwind.config.js file replace content: [], with content: ["*"],
- Add "scripts": {"start": "vite"} to your scripts in package.json
- Run npm run start command to start a dev server
Advantages of using Talwind CSS:
- No reinventing of class names required
- Your CSS doesn't grow with your HTML and Designs
- When you make a change, no risk of breaking existing templates
- If you try to make a website by using Pure CSS you will get answers to a lot of questions you have about Talwind
- Will this make your site slow?-NO Will it increase bundle size?-NO
- What about responsiveness? Yes it is responsive
- SPACE-X-3 (for giving space in text. Eg: Navbar)
- PX-3 (for giving paddin in X-axis)
- PY-2(padding in Y-axis)
- FLEX (to display the text in flexbox)
- BG-PURPLE-200 (to add color for the background with dark or light colour by setting it between 0-900)
- TEXT-RED-900 (to add color to the text)
- MX-2 (for giving margin in X-axis)
- MY-3 (margin in Y-axis)
- PT-2 (padding from top)
- PB-4 (padding from bottom)
- PL-6 (padding from left)
- PR-3 (padding from right)
- H-14 (height)
- W-2 or W-1/3 (width)
- ROUNDED-2XL (to keep a div or a image round)
- JUSTIFY-END (to start the content from thr end)
- JUSTIFY-BETWEEN (giving space evenly or space between the text)
- TEXT-6XL (large text)
- HOVER-BG-PURPLE-100 (to change the colour or anything while hovering the mouse)
- ITEMS-CENTER (to keep the items in center)
- JUSTIFY-CENTER (to keep the content in center)
- TEXT-LG (To make text large)
- ORDER-1/2/... (to give the elements order while making the website responsive)
- INSET-0 (top,bottom,right,left all get 0)
- ABSOLUTE
- STATIC
- FLEX-COL (to make the classes of column in vertical direction)
- FLEX-COL-REVERSE (to make the classes of column in horizontal direction from vertical)
- FLEX ROW
Width and Height IMP Classes
- W-[33rem]
- H-[23rem]
to hide tag in tailwind for responsive devices
- max-sm:hidden
- FONT-SANS (Properties: font-family: ui-sans-serif, system-ui, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";)
- FONT-SERIF (Properties: font-family: ui-serif, Georgia, Cambria, "Times New Roman", Times, serif;)
- FONT-MONO (Properties: font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;)
- FONT-BOLD (to make font bold)
- ITALIC/NON-ITALIC (to make font italic or non intalic)
Margin, Padding, Space Between, and Border
- MX-0,... (margin from x-axis)
- MY-0,... (margin from y-axis)
- ML-0,... (margin from left)
- MR-0,... (margin from right)
- MT-0,... (margin from top)
- MB-0,... (margin from bottom)
- SPACE-X-0 (space between elements in X-axis)
- SPCAE-Y-0 (space between elements in Y-axis)
- BORDER-SOLID/DOTTED/NONE (giving border with different styles)
- BORDER-BG-RED-700 (to give color to the border)
- PX/Y/T/B/L/R-2 (to give padding from all the different sides/ to give padding in the content in the div box)
- mx-[69px] (to give the large sizes to any class or an element. For Eg: w-[])
- SM:BG-RED-900 (Minimum width)
- MD (Medium width)
- LG (Large width)
- XLG (Extra Large Width)
- 2XL (2 Extra Large Width)
- FOCUS (to change somethng while pressing the tab button or pressing the button or when the cursor is on the button)
- ACTIVE (to change the properties while pressing button so the user can feel that it is a button)
- @apply (to apply the all classes in one and then applying them to the style.css file and then giving them a name and then applying into HTML classes)
- @layer (Eg: @layer components) (to make a part of a specific class like components or utilities. To check in the CSS by using inspect option and then checking)
When to use @apply and @layer directives:
~ I personally suggest that use this directives when you need not much then there will be no reason to use talwind css because if you are going to define a lot of classes in style.css then it is going to be a large file and there is no point for talwind css.
Customise your own config file:
- npx tailwindcss init maan
~ If you want to access the full file just type in
- npx tailwindcss init maan --full
Deploying Tailwind Website to Production
:
- Add this tag into package.json file into scripts tag:
"build": "vite build"
- npm run build