css - ::ng-deep 改变其他组件样式
问题描述
我正在使用 .md 文件在 Material for Angular 的对话框中显示信息。问题是markdown文件中的表格,当它们显示在DOM中时,没有边框。所以我尝试添加一些CSS。
::ng-deep table {
border-collapse: collapse;
border-spacing: 0;
border:2px solid black;
}
::ng-deep th {
border:2px solid black;
}
::ng-deep td {
border:1px solid black;
}
如果不添加::ng-deep
,我的桌子上没有任何样式,所以我被迫使用它。它工作正常,我的桌子现在有边框但它影响了我的其他组件,如何解决这个问题?
编辑:这是我的模板:
<div markdown [src]="data"></div>
解决方案
I hope I have clearly understood your question. If you are trying to affect the style of a child component without affecting all the other components, use :host before ::ng-deep.
:host ::ng-deep .my-class
This will only change the style in the component in which you change the style.
推荐阅读
- java - 如何计算 NanoVG 中的插入符号位置?
- nginx - 在 Nginx 反向代理后面提供服务时,Swagger UI 无法按预期工作
- jquery - 显示和隐藏 div 左右滑动动态
- mysql - Nodejs mysql如何处理超时和握手不活动超时
- javascript - 有人能告诉我这个 JS 警报有什么问题吗
- ios - 关于 Swift 中可选变量操作的问题
- github-actions - 如何在 GitHub Actions 中使用 bash 表达式设置 env var?
- python - Keras ImageGenerator:IndexError:列表索引超出范围
- xcode - jest-haste-map:Haste 模块命名冲突:尝试生成 .ipa 时反应原生
- php - Laravel:Laravel Snappy 生成错误“退出状态代码'-1073741819'”