简体   繁体   English

如何使用 CSS 在 Angular2 中的任何 PrimeNG 模块上更改颜色?

[英]How to change colors on any PrimeNG module in Angular2 using CSS?

I am working on an Angular2 project and my application is mostly built with the PrimeNG framework delivered by the same company that creates PrimeFaces.我正在处理一个 Angular2 项目,我的应用程序主要是使用由创建 PrimeFaces 的同一家公司提供的 PrimeNG 框架构建的。

I ran into a problem, where I want to customize the colors and the overall appearance of an Accordion panel, and I can't figure out how to get it done with the styleClass property.我遇到了一个问题,我想自定义手风琴面板的颜色和整体外观,但我不知道如何使用 styleClass 属性来完成它。

Where should I set it?我应该在哪里设置? WebStorm doesn't seem to like it if I do it this way:如果我这样做,WebStorm 似乎不喜欢它:

<p-accordionTab header="Personal Information" styleClass="myStyleClass">
Content
</p-accordionTab>

Furthermore, I'd love to know how should I craft my CSS in order to make it work?此外,我很想知道我应该如何制作我的 CSS 以使其工作?

Appreciate your input!感谢您的投入! :) :)

I am working with primeng as well and the way it should work based on your example is the following:我也在使用primeng,它应该根据您的示例工作的方式如下:

p-accordionTab.myStyleClass {
  width: 500px;
}

BUT there are a lot of bugreport that styleClass is not working properly.但是有很多错误报告表明 styleClass 无法正常工作。 So I advise you to use the default style classes primeng defines:所以我建议你使用primeng定义的默认样式类:

ui-accordion
ui-accordion-header
ui-accordion-content

so using them like this in style.css is working for me:所以在 style.css 中像这样使用它们对我有用:

.ui-accordion {
  width: 500px
}

You can define your .css file in your angular-cli.json the following way:您可以通过以下方式在 angular-cli.json 中定义 .css 文件:

"styles": [
        "styles.css"
]

Hope it helps!希望能帮助到你!

if your looking for easy ngClass solution here's a small example如果您正在寻找简单的 ngClass 解决方案,这里有一个小例子

(..)
<p-accordionTab [selected]="true" [ngClass]="elementFilter ? 'highLightFoundElement' : ''">
(...)

:host ::ng-deep .highLightFoundElement > div > a{
    background-color: blueviolet !important; //your choice colour
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM