• 请不要在回答技术问题时复制粘贴 AI 生成的内容
liuidetmks
V2EX  ›  程序员

有没有一种插件,写模板的时候,自动生成对应的类名

  •  
  •   liuidetmks · Jun 8, 2023 · 1779 views
    This topic created in 1113 days ago, the information mentioned may be changed or developed.
    <div class="c-ff0000 mt-90 ml-80"> </div>
    

    c-ff0000 自动生成一个类 c-ff0000,颜色为 ff0000

    mt-90 自动生成 mt-90 ,margin-top:90px

    ...

    8 replies    2023-06-08 14:12:02 +08:00
    eddiechow
        1
    eddiechow  
       Jun 8, 2023
    一种思路,你把这个逻辑告诉 chatgpt ,训练它,直到它能根据你的 html 文本准确输出 css 代码;以后你就只管往对话里面丢 html 文本就行了;
    二种思路,自己造个轮子,自己实现
    NathanDo
        2
    NathanDo  
       Jun 8, 2023
    你这个效果不就是 tailwind css 的功能吗
    molvqingtai
        3
    molvqingtai  
       Jun 8, 2023
    为什么不是提前定义好颗粒度很细的类名,推荐使用 tailwind
    liuidetmks
        4
    liuidetmks  
    OP
       Jun 8, 2023
    @molvqingtai 会不会导致没用到的类名也加载进来了
    511shajo
        5
    511shajo  
       Jun 8, 2023
    GitHub Copilot ?
    molvqingtai
        6
    molvqingtai  
       Jun 8, 2023
    @liuidetmks 既然是 CSS 框架,这种基础的功能当然是有的
    molvqingtai
        7
    molvqingtai  
       Jun 8, 2023
    @liuidetmks 完全符合先写类名再生成 css 的也不是没有,这个类 tailwind 的 virtual css 完全符合你的需求 https://css.master.co/
    lisongeee
        8
    lisongeee  
       Jun 8, 2023   ❤️ 1
    你说的这种是 unocss 的基础功能之一 <https://unocss.dev/guide/>

    unocss 更多情况下定义的是规则,而不是固定的颗粒度类

    比如可以定义 m-N -> margin: Npx ,N 是任意的数字

    还有我觉得最好用的预设 Attributify preset

    <div class="m-2 rounded text-teal-400 flex fixed" /> 可以直接写成

    <div m-2 rounded text-teal-400 flex fixed />
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   939 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 37ms · UTC 21:57 · PVG 05:57 · LAX 14:57 · JFK 17:57
    ♥ Do have faith in what you're doing.