gpt4 book ai didi

css - Angular2 根据组件选择器名称应用 css

转载 作者:行者123 更新时间:2023-11-28 15:37:37 26 4
gpt4 key购买 nike

我使用的是 ngx-bootstrap datepicker,它有 daypicker、monthpicker 和 yearpicker 作为内部组件。我想将 css 应用于 daypicker 中存在的表。

<custom-datepicker>

<datepicker> //ngx-bootstrap datepicker component
<daypicker>
<table>
//rows, want to apply some css to only this table
</table>
</daypicker>
<monthpicker>
<table>
//rows
</table>
</monthpicker>
<yearpicker>
<table>
//rows
</table>
</yearpicker>
</datepicker>

</customdatepicker>

CustomDatePickerComponent.ts

@Component({
selector: 'custom-datepicker',
templateUrl: 'custom-datepicker-component.html',
styleUrls: ['custom-datepicker-component.scss'],
})

export class CustomDatePickerComponent {

}

custom-datepicker-component.html

<datepicker></datepicker>

自定义日期选择器组件.scss

//I want to apply this css to a table which is inside daypicker. As of now it's applying to all the tables
table {
border: 1px solid lightgrey;
}

最佳答案

您可以向表格中添加一个 css 类:

<datepicker> //ngx-bootstrap datepicker component
<daypicker>
<table class="new-class">
//rows, want to apply some css to only this table
</table>
</daypicker>
...

然后使用常规类选择器:

.new-class {
// your styling
}

或者像这样向您的日期选择器或日期选择器添加一个类:

<datepicker class="new-class">
...

并使用后代选择器:

.new-class table {
// your styling
}

关于css - Angular2 根据组件选择器名称应用 css,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43961098/

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