简体   繁体   English

TailwindCSS:自己的响应式 class

[英]TailwindCSS: Own responsive class

I'm working with TailwindCSS and I created entity like this:我正在使用 TailwindCSS,并创建了这样的实体:

@layer screens {
  @responsive {
    .flex-row-around {
      @apply flex flex-row justify-around;
    }

    .flex-col-around {
      @apply flex flex-col justify-around;
    }
  }
}

I've generated stylesheet and now I'm trying to use it:我已经生成了样式表,现在我正在尝试使用它:

<div class="flex-col-around md:flex-row-around">
  ...
</div>

But my styles are not added.但是我的styles没有加。 What is done wrong?做错了什么?

TailwindCSS does not have a screens layer. TailwindCSS 没有screens层。 Looks like you're trying to create a new utility, in which case you'd want to use the utilities layer.看起来您正在尝试创建一个新的实用程序,在这种情况下,您需要使用utilities层。

@layer utilities {
  @responsive {
    .flex-row-around {
      @apply flex flex-row justify-around;
    }

    .flex-col-around {
      @apply flex flex-col justify-around;
    }
  }
}

Here's the docs for reference:这是供参考的文档:

https://tailwindcss.com/docs/functions-and-directives#layer https://tailwindcss.com/docs/functions-and-directives#layer


PS If you want to use the new just-in-time compilation, it will generate the responsive utilities automatically without needed to specify them. PS 如果您想使用新的即时编译,它将自动生成响应式实用程序,无需指定它们。 This feature is currently experimental, but I have been using it in production for a few months now without issue.此功能目前是实验性的,但我已经在生产中使用它几个月了,没有问题。

@layer utilities {
  .flex-row-around {
    @apply flex flex-row justify-around;
  }

  .flex-col-around {
    @apply flex flex-col justify-around;
  }
}

https://tailwindcss.com/docs/just-in-time-mode#enabling-jit-mode https://tailwindcss.com/docs/just-in-time-mode#enabling-jit-mode

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM