YouTip LogoYouTip

Tailwindcss Basic

Tailwind CSS is a highly customizable CSS framework that provides a set of predefined utility classes, allowing developers to quickly build and design user interfaces. Here are some basic concepts and usage of Tailwind CSS: | **Concept** | **Description** | | --- | --- | | **Utility-First** | The core of Tailwind CSS is utility classes, used for quickly setting styles, directly applied to HTML elements. | | **Responsive Prefixes** | Use prefixes like `sm:`, `md:`, `lg:`, `xl:` to control styles at different screen sizes. | | **Colors and Sizes** | Provides predefined colors (such as `bg-red-500`) and sizes (such as `text-lg`) for quick style setting. | | **Spacing** | Control padding and margin through classes like `p-`, `m-`, `pt-`, `pr-`. | | **Layout** | Provides classes like `flex`, `grid`, `float` for layout control. | | **Text Styles** | Includes utility classes for text alignment, font styles, colors and transformations, such as `text-center`, `font-bold`, `uppercase`. | | **Background and Border** | Provides utility classes for background colors, background images, border styles and colors, such as `bg-gray-200`, `border-red-500`. | | **Hover and States** | Use prefixes like `hover:`, `focus:`, `active:` to define styles for interactive states. | | **Sizing** | Use `w-`, `h-` classes to control width and height, such as `w-64`, `h-screen`. | | **Visibility** | Use classes like `visible`, `invisible` to control element visibility. | | **Grid System** | Provides CSS Grid-based utility classes, such as `grid`, `grid-cols-3`, `col-span-2`, for responsive grid layouts. | | **Custom Configuration** | Customize colors, spacing, font sizes, etc. through `tailwind.config.js` to suit project needs. | | **Dark Mode** | Supports dark mode, set styles through the `dark:` prefix, and enable dark mode functionality in configuration. | | **Plugins** | Extend functionality through plugins, adding custom utility classes or features. | | **Directives** | Use `@tailwind` directives in CSS files to import different layers of styles, such as `base`, `components`, `utilities`. | ## Concept Details ### 1. **Utility-First** Tailwind's utility classes allow developers to quickly define styles without writing CSS manually. ## Example
Tailwind Utility Classes
[Try it Β»](#) Analysis: * `text-center`: Center alignment. * `text-blue-500`: Blue text. * `font-bold`: Bold font. * * * ### 2. **Responsive Prefixes** Set styles for different screen sizes through prefixes. ## Example
Responsive Example
[Try it Β»](#) Analysis: * Default: Red background. * Small screens (β‰₯640px): Green background. * Medium screens (β‰₯768px): Blue background. * Large screens (β‰₯1024px): Yellow background. * * * ### 3. **Colors and Sizes** Tailwind provides rich predefined colors and sizes for quick application. ## Example

Text with pre-defined size and color

[Try it Β»](#) Analysis: * `text-lg`: Text size. * `text-gray-600`: Gray text. * * * ### 4. **Spacing** Set inner and outer margins of elements through spacing utility classes. ## Example
Padding and Margin Example
[Try it Β»](#) Analysis: * `p-4`: Padding of 1rem. * `m-8`: Margin of 2rem. * * * ### 5. **Layout** The provided classes can quickly implement flexible layout methods, such as Flexbox and Grid. ## Example
Item 1
Item 2
[Try it Β»](#) **Grid Example:** ## Example
1
2
3
[Try it Β»](#) * * * ### 6. **Text Styles** Control text alignment, color, size and other styles. ## Example

Centered Bold Text

[Try it Β»](#) * * * ### 7. **Background and Border** Set background colors, images and border styles through utility classes. ## Example
Background and Border Example
[Try it Β»](#) * * * ### 8. **Hover and States** Set state styles for interactive elements. ## Example [Try it Β»](#) * * * ### 9. **Sizing** Set the width and height of elements. ## Example
Width and Height
[Try it Β»](#) * * * ### 10. **Visibility** Control the display and hiding of elements. ## Example [Try it Β»](#) * * * ### 11. **Grid System** Create grid layouts using Tailwind's Grid utility classes. ## Example
1
2
3
[Try it Β»](#) * * * ### 12. **Custom Configuration** Customize the design system through configuration files. ## Example // tailwind.config.js module.exports={ theme:{ extend:{ colors:{ primary:'#1D4ED8', }, }, }, } [Try it Β»](#) * * * ### 13. **Dark Mode** Enable dark mode and define styles. ## Example
Dark Mode Example
[Try it Β»](#) * * * ### 14. **Plugins** Extend Tailwind's functionality through plugins. ## Example // tailwind.config.js const plugin = require('tailwindcss/plugin') module.exports={ plugins:[ plugin(function({ addUtilities }){ addUtilities({ '.rotate-45':{ transform:'rotate(45deg)', }, }) }), ], } * * * ### 15. **Directives** Load different layers of Tailwind through `@tailwind` directives. ## Example @tailwind base; @tailwind components; @tailwind utilities;
← Tailwindcss Utility FirstTailwindcss Installbycdn β†’