ng-multiselect-dropdown custom css

问题: I am using the ng-multiselect-dropdown. How can I override the CSS? component.html <ng-multiselect-dropdown [placeholder]="'Select Region'" [data]="dropdownLis...

问题:

I am using the ng-multiselect-dropdown. How can I override the CSS?

component.html

<ng-multiselect-dropdown [placeholder]="'Select Region'" 
    [data]="dropdownList" [(ngModel)]="selectedItems" 
    [settings]="dropdownSettings" (onSelect)="onItemSelect($event)" 
    (onSelectAll)="onSelectAll($event)" > 
</ng-multiselect-dropdown>

component.css

    .multiselect-dropdown[_ngcontent-c5] .dropdown-btn[_ngcontent-c5] {
        display: inline-block;
        border: 1px solid #adadad;
        width: 100%;
        padding: 6px 12px;
        margin-bottom: 0;
        font-size: 12px;
        font-weight: 400;
        line-height: 1.1;
        text-align: left;
        vertical-align: middle;
        cursor: pointer;
        background-image: none;
        border-radius: 4px;
   }

I need to override the default CSS with the above CSS code


回答1:

Angular by default adds some _ngcontent-xx to your component CSS file so that it won't conflict with other components.

To solve your problem you need to add below CSS in your global style.css file or another way to make your component as encapsulation: ViewEncapsulation.None meaning its CSS won't append default classes of Angular.

Solution 1: Add in global stylesheet.

style.css

.multiselect-dropdown .dropdown-btn {
    display: inline-block;
    border: 1px solid #adadad;
    width: 100%;
    padding: 6px 12px;
    margin-bottom: 0;
    font-size: 12px;
    font-weight: 400;
    line-height: 1.1;
    text-align: left;
    vertical-align: middle;
    cursor: pointer;
    background-image: none;
    border-radius: 4px;
}

Solution 2 Make component ViewEncapsulation.None

component.ts

import { Component } from '@angular/core';

@Component({
  selector: 'my-app',
  templateUrl: './app.component.html',
  styleUrls: [ './app.component.css' ],
  encapsulation: ViewEncapsulation.None // Add this line
})
export class AppComponent  {

}

Here is solution on stackblitz

Hope this will help!

  • 发表于 2019-03-20 20:59
  • 阅读 ( 311 )
  • 分类:sof

条评论

请先 登录 后评论
不写代码的码农
小编

篇文章

作家榜 »

  1. 小编 文章
返回顶部
部分文章转自于网络,若有侵权请联系我们删除