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

标签 angular bootstrap-4 ng-bootstrap

我正在使用两个 ng-bootstrap 组件 ngbDropdownngb-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/>>> 选择器?

引用 Angular 文档:

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供引用。

关于angular - 如何使用 Angular 2/Bootstrap 4 为 ng-bootstrap 控件自定义 CSS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41357847/

相关文章:

javascript - 在没有jquery的情况下缩小一个div

html - Bootstrap 4 : Use block level buttons on navbar menu on small screen but keep normal sized button when expanded

html - 引导 4 个容器重叠

javascript - Angular:将所有 FormControl 与模型更改同步

javascript - 如何在不先加载组件的情况下重定向主页?

angular - 如何以编程方式从组件类中选择 Angular 引导导航选项卡

Angular 2 - 带有 formControlName 的 ng-bootstrap 下拉菜单

Angular 10+ | ng-select的appendTo的默认值是多少

angular - 找不到名称 'HammerManager'

html - Bootstrap中的断点效果