gpt4 book ai didi

css - 更少的继承不起作用

转载 作者:太空宇宙 更新时间:2023-11-04 01:15:21 25 4
gpt4 key购买 nike

嗨,你能检查一下下面的代码吗?我想为类定义一些样式,然后为另一个类应用相同的样式。我为此使用了继承,但未使用来自父级的样式:

.parent-item {
&:not(:last-child) {
margin-right: 20px;
}
}

.child-item {
&:extend(.parent-item);
//...
}

最佳答案

只需在类(class)名称旁边添加单词all

.child-item {
&:extend(.parent-item all);
//...
}

例如

.parent-item {
color: green;
background: red;
&:not(:last-child) {
margin-right: 20px;
}

&:last-child {
color: red;
}

&:hover {
color: red;
}
}




.child-item {
&:extend(.parent-item all);
//...
}

结果会是

.parent-item,
.child-item {
color: green;
background: red;
}
.parent-item:not(:last-child),
.child-item:not(:last-child) {
margin-right: 20px;
}
.parent-item:last-child,
.child-item:last-child {
color: red;
}
.parent-item:hover,
.child-item:hover {
color: red;
}

关于css - 更少的继承不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50274209/

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