React-4-TailwindandWeatherApp PDF JNLMBK
React-4-TailwindandWeatherApp PDF JNLMBK
Agenda
tailwind setup
intro
creating weather app
Notes : Please watch the lecture to understand How weather app is created . You willl
learn how html css js based application's code flow differs from react application
@tailwind base;
@tailwind components;
@tailwind utilities;
Resources
Tailwind Installation Guide : https://tailwindcss.com/docs/guides/vite
Tailwind Official Website :https://tailwindcss.com/docs/utility-first
Tailwind cheat sheet : https://nerdcave.com/tailwind-cheat-sheet
VS code Extension
Tailwind intellisense
inline fold-> hide your tailwind classes
ES7+ React/Redux/React-Native snippet
1. Utility-First Principle
Tailwind CSS is a utility-first framework, which means it provides low-level utility classes to
build custom designs directly in your HTML or JSX. Each class corresponds to a single CSS
property or a combination of them.
2. Basic Concepts
Color:
Text color: text-{color}-{shade}
Sets the color of the text.
Background color: bg-{color}-{shade}
Sets the background color of an element.
Border color: border-{color}-{shade}
Sets the color of the border.
Effect:
The text will be blue with a medium shade.
The background will be a light shade of red.
The border will be a medium shade of green.
Spacing:
Padding: p-{size} , pt-{size} , pr-{size} , pb-{size} , pl-{size} , px-
{size} , py-{size}
Adds space inside the element.
p-4 : Adds padding of 1rem (16px) on all sides.
m-2 : Adds margin of 0.5rem (8px) on all sides.
Effect:
The element will have 1rem (16px) padding on all sides.
The element will have 0.5rem (8px) margin on all sides.
Sizing:
Width: w-{size}
Sets the width of an element.
Height: h-{size}
Sets the height of an element.
Max-width: max-w-{size}
Sets the maximum width of an element.
Max-height: max-h-{size}
Sets the maximum height of an element.
Effect:
The element will have a width of 50% of its parent.
The element will have a fixed height of 8rem (128px).
The element's width will not exceed 20rem (320px).
Typography:
Font size: text-{size}
Sets the font size of the text.
Font weight: font-{weight}
Sets the thickness of the font.
Line height: leading-{size}
Sets the space between lines of text.
Text alignment: text-{left|center|right|justify}
Aligns the text horizontally.
Effect:
The text will have a font size of 1.125rem (18px).
The text will be bold.
The lines will have minimal space between them.
The text will be centered horizontally.
Flexbox:
Display: flex
Applies a flexbox layout to the element.
Flex direction: flex-{row|col}
Sets the direction of the flex items.
Justify content: justify-{start|center|end|between|around|evenly}
Aligns flex items along the main axis.
Align items: items-{start|center|end|stretch|baseline}
Aligns flex items along the cross axis.
Gap: gap-{size}
Sets the space between flex items.
Effect:
The element will have a flex layout with a vertical direction.
Flex items will be centered along both axes.
There will be a gap of 1rem (16px) between flex items.
Positioning:
Position: static , relative , absolute , fixed , sticky
Sets the position type of an element.
Effect:
The element will be positioned relative to its normal position.
It will be moved 0.5rem (8px) from the top and 1rem (16px) from the left.
Borders:
Border width: border , border-{size} , border-t-{size} , border-r-{size} ,
border-b-{size} , border-l-{size}
Sets the width of the border on all or specific sides.
Border radius: rounded , rounded-{size} , rounded-t-{size} , rounded-r-
{size} , rounded-b-{size} , rounded-l-{size}
Sets the rounding of the corners of the element.
Border style: border-{style}
Sets the style of the border (e.g., solid, dashed).
Effect:
The element will have a border with a width of 4px.
The border will be dashed.
The corners will be rounded with a large radius.
Backgrounds:
Background size: bg-{auto|cover|contain}
Sets the size of the background image.
Background position: bg-{center|top|right|bottom|left}
Sets the position of the background image.
<div className="bg-cover bg-center" style={{ backgroundImage:
'url(path/to/image.jpg)' }}>
Background Example
</div>
Effect:
The background image will cover the entire element.
The background image will be centered.
Effects:
Box shadow: shadow , shadow-{size}
Adds a shadow effect to the element.
Opacity: opacity-{value}
Sets the transparency level of the element.
Effect:
The element will have a large shadow.
The element will be 75% opaque (25% transparent).
Transitions & Animations:
Transition: transition , transition-{property} , duration-{time} , ease-
{type}
Adds a transition effect when properties change.
Effect:
The element will have a transition effect applied to all properties.
The transition will last 500ms.
The transition will ease in and out smoothly.
On hover, the element will scale up to 105% of its original size.
Pseudo-classes:
Hover: hover:{utility}
Applies styles when the element is hovered.
Focus: focus:{utility}
Applies styles when the element is focused.
Active: active:{utility}
Applies styles when the element is active (clicked).
Effect:
The button will have a blue background.
On hover, the background will change to a darker blue.
On focus, the background will change to an even darker blue.
When active, the background will be a medium-dark blue.