gpt4 book ai didi

css - 如何将相同的样式应用于所有直接子类?

转载 作者:行者123 更新时间:2023-11-28 10:30:30 24 4
gpt4 key购买 nike

less我有以下内容:

.some-class{
> li{
a{

color: white;
background: @fti-lightgrey;
border-radius: 0px;
padding: 1px 15px;

// a color for the partcular tab that is chosen. (the color for each tab can be set inside mura)
&.orange{
&:hover{ background: @fti-orange; }
&:hover{ color: white; }
}
&.black {
&:hover{ background: black; }
&:hover{ color: white; }
}
&.topaz{
&:hover{ background: @fti-topaz; }
&:hover{ color: white; }
}

}
}
}

如何避免编写 &:hover{ color: white; } 多次?
有没有办法将此行应用于 a 标记内某处的所有直接类后代?

最佳答案

这取决于想要的结果。

你想要:1) 默认情况下为白色悬停颜色,无论它是否也具有 .orange、.black 或 .topaz 类之一?

.some-class{
> li{
a{

color: white;
background: @fti-lightgrey;
border-radius: 0px;
padding: 1px 15px;

// a color for the partcular tab that is chosen. (the color for each tab can be set inside mura)
&.orange{
&:hover{ background: @fti-orange; }
}
&.black {
&:hover{ background: black; }
}
&.topaz{
&:hover{ background: @fti-topaz; }
}

}
a:hover{ color: white; }
}

2) 或者如果它具有.orange、.black、.topaz 类之一,您是否希望它在悬停时为白色?

.some-class{
> li{
a{

color: white;
background: @fti-lightgrey;
border-radius: 0px;
padding: 1px 15px;

// a color for the partcular tab that is chosen. (the color for each tab can be set inside mura)
&.orange{
&:hover{ background: @fti-orange; }
}
&.black {
&:hover{ background: black; }
}
&.topaz{
&:hover{ background: @fti-topaz; }
}

}
a:hover {
&.orange, &.black, &.topaz{
color: white;
}
}
}

关于css - 如何将相同的样式应用于所有直接子类?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23551428/

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