css - Angular:组件标签上的样式类
问题描述
是否可以在组件上应用这样的类或样式?
元素组件
@Component({
selector: 'app-element',
templateUrl: './element.component.html',
styleUrls: ['./element.component.scss']
})
容器组件模板
<app-element class="button"></app-element>
全局.css
.button {
background :red;
}
解决方案
是的,这是可能的。另一种方法是:host
在您的组件样式中使用:
:host(.customClass) {
background: blue;
}
您也可以像这样直接向组件添加样式:
:host {
background: blue;
}
或在您的 .ts 文件中:
@Component({
selector: 'your-component',
template: 'your-component.html',
host: {'class': 'customClass'}
})
:host
您可以在此处阅读更多信息。
推荐阅读
- sql - 将日期标准化为从同一来源开始的期间
- php - Laravel Jetstream - 导航 - 将路线名称数据传递给:活动导航
- c# - AutoMapper ForPath - 路径中有集合
- java - 如何在Java中找到具有负增量以及正负值的随机值?
- docker - 是否有任何可能的解决方案可以在 Jenkins 的帖子部分(声明性管道)下运行 docker?
- python - “groupby”返回每个分组项目的出现百分比
- python-3.x - Weasyprint 输出不显示大部分原始网页?
- javascript - 我无法理解这段代码中的 parseInt 方法
- c++ - 您可以在 if 语句中使用数字范围吗?
- flutter - 我在哪里可以获得 VSCode 中 dart 启动的配置?