gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-29 18:03:53 25 4
gpt4 key购买 nike

我正在使用两个 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com