Primeng的P-Card组件简单地赢了CSS更改

发布于 2025-02-10 16:13:01 字数 1437 浏览 1 评论 0原文

我需要在应用程序中动态更改P-Card组件。但这根本不起作用... 我到目前为止尝试过的是我尝试过的:

<div class="card-image-comp">
            <p-card [class.activeCard]="profileCardSelected === 1" (click)="selectProfileType(1)">
                <img src="../../../assets/icons/person.png">
            </p-card>
            <p>Paciente</p>
</div>
<div>
            <p-card [class.activeCard]="profileCardSelected === 2" (click)="selectProfileType(2)">
                <img src="../../../assets/icons/estetoscopio.png">
            </p-card>
            <p>Profissional de Saúde</p>
</div>
...
My function:
    selectProfileType(numCard: number){
        this.profileCardSelected = numCard;
    }

这部分工作正常,问题是该组件并不遵守新课程。

我已经尝试了普通的事情:

.activeCard {
  background-color: black;
}

... 
div {
  .activeCard {
    background-color: black;
  }
}

... 
.personalCardComp {
  .activeCard {
    background-color: black;
  }
}

... and even some nasty stuff
:host {
  ::ng-deep .activeCard {
    background-color: black;
  }
}

...
:host {
  ::ng-deep p-card.p-element.activeCard {
    background-color: black;
  }
}

正如我之前说的,该课程正确地应用了,但是当我将CSS应用于P-Card的Div儿童时,该卡仅更改...

i.sstatic.net/e9xtx.png“ rel =“ nofollow noreferrer 如果我可以将班级应用于这个div的孩子,那就可以了...有没有办法这样做?将课程应用于p-card,但div子女obbey ...

I need to dynamically change a p-card component in my APP. But it's simply not working...
Heres what I've tried so far :

<div class="card-image-comp">
            <p-card [class.activeCard]="profileCardSelected === 1" (click)="selectProfileType(1)">
                <img src="../../../assets/icons/person.png">
            </p-card>
            <p>Paciente</p>
</div>
<div>
            <p-card [class.activeCard]="profileCardSelected === 2" (click)="selectProfileType(2)">
                <img src="../../../assets/icons/estetoscopio.png">
            </p-card>
            <p>Profissional de Saúde</p>
</div>
...
My function:
    selectProfileType(numCard: number){
        this.profileCardSelected = numCard;
    }

This part is working just fine, the issue is that the component is not obeying it's new class.

I've tried the normal stuff:

.activeCard {
  background-color: black;
}

... 
div {
  .activeCard {
    background-color: black;
  }
}

... 
.personalCardComp {
  .activeCard {
    background-color: black;
  }
}

... and even some nasty stuff
:host {
  ::ng-deep .activeCard {
    background-color: black;
  }
}

...
:host {
  ::ng-deep p-card.p-element.activeCard {
    background-color: black;
  }
}

As I said before, the class is applied correctly, but the card only changes when I apply the css to the div children of the p-card...

enter image description here

Basically if I could apply the class to this div children It would work just fine... Is there a way to do so? Apply the class to p-card but the div children obbey...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

零時差 2025-02-17 16:13:01

确保正确导入您的 .scss 文件,然后:

:host ::ng-deep {
  .p-card.p-component {
    background: black;
  }
}

Be sure to properly import your .scss file and then:

:host ::ng-deep {
  .p-card.p-component {
    background: black;
  }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文