gpt4 book ai didi

less - 如何使用 less 定位类中的元素?

转载 作者:行者123 更新时间:2023-12-03 23:43:02 26 4
gpt4 key购买 nike

我想使用 less 来定位类中的特定元素。

在这种情况下,我想定位类 button 的元素,但在此范围内我想定位一个 anchor 标签 a .

目前我有:

.button {
/* lots of bits and pieces go here, hence
the need to keep it at a class level
*/


/* further down, but still in .button */
/* Attempt 1 - fails: compiled = a .button (note the space)
a& {
height:20px;
}

/* Attempt 2 - fails: compiled = .buttona
&a {
height:20px;
}
}

我基本上希望它编译为:
a.button

这样我就可以创建元素,例如:
<a class="button">
<button class="button">

但是当它是一个 anchor 时稍微改变它。我不想扔 it's a bug in less!卡太早了,但如果我使用 &.another-class它按预期工作(编译: .button.another-class ,但在定位元素时不是

最佳答案

您使用的是less的旧版本。下面的代码使用less 1.3.3生成正确的CSS

.button {
a& {
height:20px;
}
}

产生:
a.button {
height: 20px;
}

关于less - 如何使用 less 定位类中的元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14169560/

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