如何使用Angular 2 / Bootstrap 4为ng-bootstrap控件自定义CSS

前端之家收集整理的这篇文章主要介绍了如何使用Angular 2 / Bootstrap 4为ng-bootstrap控件自定义CSS前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在使用两个ng-bootstrap组件ngbDropdown和ngb-pagination,我希望它们彼此垂直对齐.

enter image description here

ngb-pagination组件使用.pagination类创建此HTML,边距为1rem

<nav>
  <ul ng-reflect-class-name="pagination pagination-sm" class="pagination pagination-sm">
  </ul>
</nav>

我试图使用以下内容改变我的Angular 2组件.

@Component({
    selector: 'wk-company-list',template: require('./list.html'),styles: [`
        .pagination {
            margin-top: 0;
            background-color: greenyellow;
        }
    `]
})

这是带有这两个控件的完整HTML页面

<ag-grid-ng2 #agGrid style="width: 100%; height: 350px;" class="ag-fresh"
             [gridOptions]="gridOptions"
             rowSelection="multiple"
             (cellClicked)="onCellClicked($event)"
             (selectionChanged)="onSelectionChanged($event)">

</ag-grid-ng2>


<div class="align-middle">

    <span ngbDropdown class="d-inline-block">
        <button class="btn btn-outline-primary btn-sm" id="dropdownMenu2" ngbDropdownToggle>25</button>
        <div class="dropdown-menu" aria-labelledby="dropdownMenu2">
            <button class="dropdown-item">25</button>
            <button class="dropdown-item">50</button>
            <button class="dropdown-item">100</button>
            <button class="dropdown-item">200</button>
            <button class="dropdown-item">1000</button>
            <span class="text-muted">Total: {{vm.pagination.total}}</span>
        </div>
    </span>
    <span class="float-xs-right">
        <ngb-pagination
                style="margin-top: 0"
                (pageChange)="onPageChange($event)"
                [(page)]="vm.pagination.no"
                [pageSize]="vm.pagination.size"
                [collectionSize]="vm.pagination.total"
                size="sm"
                [maxSize]="5"
                [ellipses]="false"
                [rotate]="true"
                [boundaryLinks]="true">
        </ngb-pagination>
    </span>
</div>

解决方法

您是否尝试过使用/ deep /或>>>组件样式中的选择器?

引用角度文档:

Component styles normally apply only to the HTML in the component’s own template.
We can use the /deep/ selector to force a style down through the child component tree into all the child component views. The /deep/ selector works to any depth of nested components,and it applies both to the view children and the content children of the component.

请参阅https://angular.io/docs/ts/latest/guide/component-styles.html以供参考.

猜你在找的Angularjs相关文章