有没有可能动态地给现有的类分配一个类?我正在尝试为第一个子元素分配样式,就像这样:
.active {
color: red;
}
item:first-child .item_text {
background: rgba(255, 255, 255, 1);
/* make it active class */
}
有没有可能动态地给现有的类分配一个类?我正在尝试为第一个子元素分配样式,就像这样:
.active {
color: red;
}
item:first-child .item_text {
background: rgba(255, 255, 255, 1);
/* make it active class */
}
.active,
item:first-child .item_text {
color: red;
}
item:first-child .item_text {
background: rgba(255, 255, 255, 1);
}
如果您使用像LESS或SASS这样的CSS预处理器,就可以实现这一点。它们可以扩展CSS的功能,例如包含/扩展类等。
在LESS中
item:first-child .item_text {
background: rgba(255, 255, 255, 1);
.active;
}
color: red;
行。item:first-child .item_text {
background: rgba(255, 255, 255, 1);
@extend .active;
}