gpt4 book ai didi

Using Square Brackets in Class Names with Pug and Tailwind CSS(在带有PUG和TailWind CSS的类名中使用方括号)

转载 作者:bug小助手 更新时间:2023-10-24 19:53:25 27 4
gpt4 key购买 nike



I'm trying to use both Pug and Tailwind CSS for a project. I encountered an issue when trying to utilize Tailwind's custom values syntax (using square brackets) in a Pug template.

我正在尝试使用PUG和尾风的CSS为一个项目。在尝试在PUG模板中使用TailWind的定制值语法(使用方括号)时,我遇到了一个问题。


I understand that h-[127px] is a valid Tailwind class for setting a custom height. However, it seems that Pug does not like the square brackets.

我知道h-[127px]是设置自定义高度的有效TailWind类。然而,帕格似乎不喜欢方括号。


Is there a way to integrate square bracket syntax in Pug while using Tailwind CSS?
If not, what's the recommended workaround to use custom values from Tailwind within a Pug template?
Thank you for any assistance!

有没有办法在PUG中集成方括号语法,同时使用TailWind CSS?如果不是,在PUG模板中使用来自TailWind的自定义值的推荐解决方法是什么?感谢您的帮助!


更多回答

Shot in the dark, can you try escaping the slash? ie h-\[127px\]

是在黑暗中被枪杀的,你能试着从斜线中逃脱吗?IE h-\[127px\]

优秀答案推荐

Square brackets (even escaped) won't work using Pug's shorthand class syntax:

使用PUG的速记类语法时,方括号(甚至转义)将不起作用:


// won't work
img.avatar.h-[127px](src='foobar.png')

// also won't work
img.avatar.h-\[127px\](src='foobar.png')

But you can use square brackets with the regular attribute syntax:

但您可以在常规属性语法中使用方括号:


// will work
img(class='avatar h-[127px]', src='foobar.png')

Also note you can mix the class shorthand with a regular class attribute, so you can keep using the shorthand for all of the classes without brackets, and only use the longhand for the offending classes:

还请注意,您可以将类速记与常规类属性混合使用,这样您就可以继续对所有不带括号的类使用速记,而只对有问题的类使用速记:


// will work, and is equivalent to the previous example
img.avatar(class='h-[127px]', src='foobar.png')

更多回答

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com