gpt4 book ai didi

css - LESS css 使用 mixin 设置动态背景图片

转载 作者:技术小花猫 更新时间:2023-10-29 10:08:30 26 4
gpt4 key购买 nike

我正在使用 LESS CSS .

我目前正在使用带有变量的 Mixins。

这样的东西没问题:

.border-radius (@radius) { border-radius: @radius; }

#header { .border-radius(4px); }

不是:

.bg-img(@img) { background-image:url(@img); }

#logo { .bg-img("../images/logo.jpg"); }

我已经尝试在背景图像中使用 '& "的组合:url ('') & ("") 但随后它会尝试将图像获取为 images/@ img 而不是图像名称。否则它会给我一个错误
Cannot call method 'charAt' of undefined

我认为一直写 background-image:url() 太乏味了,这可能吗..?

最佳答案

:) 得到我的答案!

在我的例子中需要这样使用:

.bg-img(@img) { background-image:url("@{img}"); }

#logo { .bg-img("../images/logo.jpg"); }

关于css - LESS css 使用 mixin 设置动态背景图片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6334644/

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