gpt4 book ai didi

css - 混合 css 模块类和 bootstrap active

转载 作者:太空宇宙 更新时间:2023-11-04 09:39:36 24 4
gpt4 key购买 nike

在我正在处理的一个元素中,我们将 css 模块与 postcss(还有 postcss-cssnextpostcss-include)一起使用。我们也有 bootstrap 作为全局提供的依赖项。

在给定的组件中,我确实有一个按钮的自定义类。所以我的按钮有以下类:btn btn-custom

根据需求我想修改按钮处于激活状态时的外观。因为该 Bootstrap 具有以下选择器:.btn.active, .btn:active。覆盖伪类是比较容易的部分。 .active 类是它变得棘手的地方。

在我的 css 文件中,我尝试了几种方法来处理这个问题,但似乎都没有用。以下是我尝试过的一些方法:

.btn-custom {
&.active, &:active {}
@nested :global &.active, &:active {}
@nested :global & { &.active, &:active: {} }
@nested :global { &.active, &:active: {} }
}

:global {
.btn-custom { &.active, &:active {} }
.btn { &.active, &:active {} }
}

有人知道如何实现吗?

最佳答案

全局目标类需要用括号括起来,像这样:

.btn-custom {
color: red;
}

.btn-custom:global(.active) {
color: blue;
}

嵌套也是如此:

.btn-custom {
&:global(.active),
&:active {}
}

最后一个未经测试,我想 PostCSS 插件的顺序在这里很重要。

关于css - 混合 css 模块类和 bootstrap active,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40043154/

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