zoukankan      html  css  js  c++  java
  • [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>
  • 相关阅读:
    算法之递归
    初读 c# IL中间语言
    sql语句转为Model
    WPF-悬浮窗(类似于360)
    call,apply
    作用域题目
    css BFC
    数组扁平化 flatten
    常见的异步题
    setTimeout、Promise、Async/Await 的区别
  • 原文地址:https://www.cnblogs.com/Answer1215/p/8809875.html
Copyright © 2011-2022 走看看