less css,定义空字符串变量

发布于 2024-12-21 08:51:16 字数 419 浏览 2 评论 0原文

我想定义一个变量,在某些情况下可能为空 @prefix: "";

并像这样使用它 src: url("@{prefix}/path/to/something");

问题是它编译成 src: url("""/path/to/something");

如何定义一个可以编译的空字符串变量 src: url("/path/to/something");

更新: 问题已结束 https://github.com/cloudhead/less.js/issues/532

I want to define a variable, which could be empty in some cases
@prefix: "";

and to use it like this
src: url("@{prefix}/path/to/something");

the problem is that it compiles into
src: url("""/path/to/something");

How to define an empty string variable, that can be compiled in
src: url("/path/to/something");

Update:
Issue closed
https://github.com/cloudhead/less.js/issues/532

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

空袭的梦i 2024-12-28 08:51:16

刚刚找到了一种方法来做到这一点...转义空字符串 @prefix: ~'';

我使用经常保留的 box-shadow inset 选项遇到了这个问题空的。

Just found a way to do this... escape an empty string @prefix: ~'';

I ran into this with the box-shadow inset option that will often remain empty.

酒与心事 2024-12-28 08:51:16

我不确定这是否可能在更少的时间内实现。您可以创建一个 mixin 函数,它返回带有前缀的路径。如果您想偶尔更改前缀并且只需在一个地方执行此操作,这将很有用。

.prefixRed(@path: @defaultpath) {
    background: transparent url("red/@{path}");
}
.prefixBlue(@path: @defaultpath) {
    background: transparent url("blue/@{path}");
}

I'm not sure this is possible in less. You could make a mixin function which returns the path with the prefix prepended to it. This would be useful if you want to change the prefix once in awhile and only have to do it in one place.

.prefixRed(@path: @defaultpath) {
    background: transparent url("red/@{path}");
}
.prefixBlue(@path: @defaultpath) {
    background: transparent url("blue/@{path}");
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文