File tree Expand file tree Collapse file tree 2 files changed +35
-1
lines changed Expand file tree Collapse file tree 2 files changed +35
-1
lines changed Original file line number Diff line number Diff line change @@ -10,7 +10,7 @@ pairing with smart people at Hashrocket.
1010
1111For a steady stream of TILs, [ sign up for my newsletter] ( https://crafty-builder-6996.ck.page/e169c61186 ) .
1212
13- _ 1393 TILs and counting..._
13+ _ 1394 TILs and counting..._
1414
1515---
1616
@@ -1235,6 +1235,7 @@ _1393 TILs and counting..._
12351235
12361236### Tailwind CSS
12371237
1238+ - [ Apply Tailwind Classes To Existing CSS Class] ( tailwind/apply-tailwind-classes-to-existing-css-class.md )
12381239- [ Base Styles For Text Link] ( tailwind/base-styles-for-text-link.md )
12391240- [ Specify Paths For Purging Unused CSS] ( tailwind/specify-paths-for-purging-unused-css.md )
12401241- [ Use Tailwind Typography Prose In Dark Mode] ( tailwind/use-tailwind-typography-prose-in-dark-mode.md )
Original file line number Diff line number Diff line change 1+ # Apply Tailwind Classes To Existing CSS Class
2+
3+ Let's say I have some HTML in my app that I don't totally control -- maybe it's
4+ a 3rd-party component or it was rendered by a markdown transformer. Regardless,
5+ I am ending up with some HTML where tags have class names that I'd like to
6+ style.
7+
8+ ``` html
9+ <div class =" code-block" >
10+ <!-- ... -->
11+ </div >
12+ ```
13+
14+ If it was HTML (or JSX) that I was writing, I could stick whatever tailwind
15+ class names I wanted on the various tags to get the styling just right. But
16+ since I don't control it directly, I have to find another way to _ apply_ those
17+ tailwind classes.
18+
19+ Enter [ tailwind's ` @apply `
20+ directive] ( https://tailwindcss.com/docs/functions-and-directives#apply ) . With
21+ this, I can target an existing class selector with any tailwind utility classes.
22+ Add lines like the following to your root ` tailwind.css ` file.
23+
24+ ``` css
25+ @tailwind base;
26+ @tailwind components;
27+ @tailwind utilities;
28+
29+ /* additional styling here 👇 */
30+ .code-block {
31+ @apply bg-gray- 200 rounded-md p- 4;
32+ }
33+ ```
You can’t perform that action at this time.
0 commit comments