angular在父組件設置子組件樣式


:host-context():可以對宿主及其子元素設置css,()里是對組件的祖先元素添加的類名。

基本用法:

FatherComponent.html:
<div class="father">
  <app-child></app-child>
</div>

ChildComponent.html:
<div class="child"></div>

 

ChildComponent.css:
:host-context(.father) .child{
//css
}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM