码迷,mamicode.com
首页 > Windows程序 > 详细

[Tailwind] Abstract Utility Classes to BEM Components in Tailwind

时间:2018-04-12 19:58:15      阅读:256      评论:0      收藏:0      [点我收藏+]

标签:element   ati   you   pre   htm   class   技术   style   alt   

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

标签:element   ati   you   pre   htm   class   技术   style   alt   

原文地址:https://www.cnblogs.com/Answer1215/p/8809875.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!