Editing CSS for PrimeNG Components

浪尽此生 提交于 2020-01-13 07:05:10

问题


I am currently developing a user interface using Angular 4, Angular Materials and PrimeNG components.

The latest component I am battling with is the MultiSelect Component from PrimeNG: https://www.primefaces.org/primeng/#/multiselect

I am simply just trying to make the component's width fit 100% of the parent component.

Is there a specific process I need to follow to edit CSS classes for this component? The documentation says to use "Style" for inline - does this mean:

<p-multiSelect [options]="cars" [(ngModel)]="selectedCars" [defaultLabel]="defaultLabel" style="width: 100%;"></p-multiSelect>

Because this did not work.

It also says to use "styleClass" as a property to add a styling CSS class. How do you use this?

Lastly, they provide a list of the CSS classes the PrimeNG component uses on the website (e.g. ui-multiselect). When I attempt to modify 'ui-multiselect' by declaring it within the Angular components CSS, it still doesn't work.

Any ideas? What am I doing wrong?


回答1:


For inline PrimeNG styling, use something like this:

[style]="{'width': '100%'}"

To use styleClass simply add:

styleClass="example-css-class"

This way, for example, you can style multi select input field with many different style classes, eg. Bootstrap's form-control.

When you operate with PrimeNG ui's, be sure to put them into components .css. If you use global styles.css, you'll have to override the PrimeNG files in .angular-cli.json. You can do it by editing styles array like this:

"../node_modules/primeng/resources/primeng.min.css",
"../node_modules/primeng/resources/themes/omega/theme.css",
"styles.css"

When the styles.css are put after the primeng resources, it is loaded after the primeng's, which will override the styles.



来源:https://stackoverflow.com/questions/45499851/editing-css-for-primeng-components

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!