-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.jsx
144 lines (141 loc) · 5.73 KB
/
App.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
import "./App.css";
import Description from "./Description";
import Hr from "./Hr";
import Title from "./Title";
function App() {
return (
<div className="container mx-auto px-4 py-12">
<h1 className="text-4xl font-bold max-w-3xl mb-2 mx-auto text-center">
Tips and Tricks with Tailwind CSS
</h1>
<h2 className="mb-8 text-base text-gray-500 sm:text-lg max-w-3xl mx-auto text-center">
Learn how to tailor your Tailwind CSS project with the help of Tailwind
CSS examples shown below.
</h2>
<main className="grid grid-cols-1 gap-8 md:grid-cols-2">
<section className="bg-gray-50 p-8 rounded-2xl">
<Title text="1: Delegate classes to parent" />
<Description>
The below nav items has <b>text-2xl</b> on ul tag instead of having
on each li tag. This helps to avoid writing it multiple times.
</Description>
<Hr />
<nav>
<ul className="flex flex-wrap text-2xl text-fuchsia-800 text-opacity-70 p-1">
<li className="mr-4 bg-gray-200 text-blue-400 p-1">
<a href="#">Home</a>
</li>
<li className="mr-4 p-1">
<a href="#">About</a>
</li>
<li className="mr-4 p-1">
<a href="#">Contact</a>
</li>
</ul>
</nav>
</section>
<section className="bg-gray-50 p-8 rounded-2xl">
<Title text="2: Adding space between elements" />
<Description>
Instead of using <b>gap-*, margin, padding</b> property on each
child, we can use the <b>space-x-*, space-y-*</b> property on the
parent.
</Description>
<Hr />
<ul className="flex flex-row space-x-5">
<li className="size-16 bg-red-400">Item 1</li>
<li className="size-16 bg-red-500">Item 2</li>
<li className="size-16 bg-red-600">Item 3</li>
</ul>
</section>
<section className="bg-gray-50 p-8 rounded-2xl">
<Title text="3: Don't overuse @apply utility classes" />
<Description>
Using custom classname like <b>.nav-items</b> and adding tailwind
classes in css files using <b>@apply</b> can cause problems like
name collisions and hard to maintain code. It is ok to use it when
working with third party libraries.
</Description>
<Hr />
<ul className="nav-items">
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
</ul>
</section>
<section className="bg-gray-50 p-8 rounded-2xl">
<Title text="4: Adding opacity to background & text" />
<Description>
You can apply opacity to background and text using{" "}
<b>.bg-opacity-*</b> and <b>.text-opacity-*</b> tailwind classes.
</Description>
<Hr />
<div className="bg-teal-500 bg-opacity-100 w-[200px]">
<p className="text-blue-900 text-opacity-70">tailwind css text</p>
</div>
</section>
<section className="bg-gray-50 p-8 rounded-2xl">
<Title text="5: Adding Transition & Animation " />
<Description>
To animate elements <b>transition-*</b> and <b>duration-* </b>
classes can be used. Tailwind also has predefined animations.
</Description>
<Hr />
<button className="p-2 text-white rounded bg-blue-500 hover:bg-blue-700 active:bg-blue-900 transition-colors duration-200">
Buy Items
</button>
</section>
<section className="bg-gray-50 p-8 rounded-2xl">
<Title text="6: Group hover example" />
<Description>
Hover on button, will rotate the icon present inside the button as a
separate child element. This can be achieved by adding <b>group</b>{" "}
classname on parent and <b>group-hover:property</b> classname on
child element.
</Description>
<Hr />
<button className="p-2 text-white rounded group bg-blue-500 hover:bg-blue-700 active:bg-blue-900 transition-colors duration-200">
<span>Click!</span>
<span className="ml-2 inline-block group-hover:rotate-90 duration-300">
→
</span>
</button>
</section>
<section className="bg-gray-50 p-8 rounded-2xl">
<Title text="7: Using pseudo classes" />
<Description>
The below button has a background color added using <b>after</b>{" "}
pseudo class. One can also use <b>before</b> pseudo classes the same
way.
</Description>
<Hr />
<button className="p-2 relative after:absolute after:bg-green-300 after:inset-0 after:z-0">
<h6 className="z-10 relative">BUTTON </h6>
</button>
</section>
<section className="bg-gray-50 p-8 rounded-2xl">
<Title text="8: Adding Custom input values" />
<Description>
The value of any classname property can be customize using
<b> property-[value]</b> syntax. E.g <b>text-[#007bff]</b>,{" "}
<b>text-[200px]</b>
</Description>
<Hr />
<h5 className="text-[#007bff] text-[4rem]">Hello World</h5>
</section>
</main>
<footer className="mt-6 text-center">
Code available on{" "}
<a
href="https://github.com/nirajrajgor/tailwindcss-tips"
target="_blank"
rel="noreferrer"
className="font-medium text-blue-600 hover:underline"
>
Github
</a>
</footer>
</div>
);
}
export default App;