[Tailwind] Abstract Utility Classes to BEM Components in Tailwind
Posted Answer1215
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[Tailwind] Abstract Utility Classes to BEM Components in Tailwind相关的知识,希望对你有一定的参考价值。
When creating UIs with utility classes, a lot of repetition can occur within the html markup. In this lesson, we see how this concern can be addressed by extracting a group of tailwind utility classes into a component classname. We create a Blocks Elements and Modifier (BEM) button component with a few style modifiers, that can be used everywhere in our project.
It is not reuseable when you only apply utilities class to the element.
The button way is:
<button class="button">Button</button>
So to create .button class and apply all the utilities class from tailwind, we can do:
.button { @apply .font-bold .py-2 .px-4 .rounded; } .button-blue { @apply .bg-blue .text-white; } .button-blue:hover { @apply .bg-blue-dark; }
Then we can use it like:
<button class="button button-blue">Button</button>
以上是关于[Tailwind] Abstract Utility Classes to BEM Components in Tailwind的主要内容,如果未能解决你的问题,请参考以下文章
text BLOG SAP con molte info utili
Tailwind.css — 如何使用 Tailwind 实现 last-child?
[Tailwind] Create Custom Utility Classes in Tailwind