【问题标题】:How to use layout variants in tailwind-css using jit?如何使用 jit 在 tailwind-css 中使用布局变体?
【发布时间】:2021-09-17 04:18:06
【问题描述】:

像 youtube.com 或 twitch.tv 这样的网站有一个我称之为替代视图的功能,与默认视图相比,播放器使用更多的屏幕空间。

如何使用即时编译器在 tailwindcss 中实现?

<html class="player-large">
<body>
    <!-- like using the build in darkMode: 'class' feature -->
  </div>
</body>
</html>

布局将使用顺风网格功能完成,html 标签上的“player-large”类用于切换视图。

我希望像这样使用它:

<video class="lg:col-span-2 lg:large-player:col-span-full">...</video>

如何做到这一点?

【问题讨论】:

    标签: css tailwind-css jit


    【解决方案1】:

    您可以创建新的变体

    tailwind.config.js

    const plugin = require('tailwindcss/plugin')
    
    module.exports = {
      mode: 'jit',
      theme: {
        extend: {},
      },
      variants: {},
      plugins: [
    
        plugin(function({ addVariant, e }) {
          addVariant('large-player', ({ modifySelectors, separator }) => {
            modifySelectors(({ className }) => {
              return `.large-player .${e(`large-player${separator}${className}`)}` // this is CSS selector
            })
          })
        })
    
      ],
    }
    

    布局

    <div class="large-player">
    
    <div class="grid grid-cols-3 gap-6">
      <div class="h-32 bg-red-500 lg:col-span-2 lg:col-span-2 lg:large-player:col-span-full"></div>
      <div class="h-32 bg-red-500"></div>
    </div>
    
    </div>
    

    DEMO here - 切换large-player 类以查看效果

    【讨论】:

    • 哇,这很容易添加。感谢您的快速答复
    猜你喜欢
    • 1970-01-01
    • 2021-02-28
    • 1970-01-01
    • 2022-01-19
    • 1970-01-01
    • 1970-01-01
    • 2021-09-18
    • 2021-05-02
    • 2021-06-29
    相关资源
    最近更新 更多