加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

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

发布时间:2020-12-17 17:04:53 所属栏目:安全 来源:网络整理
导读:我正在使用两个ng-bootstrap组件ngbDropdown和ngb-pagination,我希望它们彼此垂直对齐. ngb-pagination组件使用.pagination类创建此HTML,边距为1rem nav ul ng-reflect-class-name="pagination pagination-sm" class="pagination pagination-sm" /ul/nav 我
我正在使用两个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以供参考.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读