Unable to style encapsulated components
See original GitHub issueIn the example below I use the list component and try to apply a background color on list items when the item is hovered. However _ngcontent
attributes are added to my CSS selectors and some of the elements generated HTML seems to not receive this attribute making impossible to apply any style to it.
http://plnkr.co/edit/Sgr8DI9hWnOItPWR9Tva?p=preview
Original Style
I’ve tried different rules just in case…
md-list-item:hover {
background:red;
}
md-list-item:hover > div{
background:green;
}
md-list-item > div:hover{
background:blue;
}
Injected Style
md-list-item[_ngcontent-pgx-1]:hover {
background:red;
}
md-list-item[_ngcontent-pgx-1]:hover > div[_ngcontent-pgx-1]{
background:green;
}
md-list-item[_ngcontent-pgx-1] > div[_ngcontent-pgx-1]:hover{
background:blue;
}
Generated HTML
<md-list _ngcontent-pgx-1="" dense="" role="list">
<md-list-item _ngcontent-pgx-1="" role="listitem" class="md-2-line">
<div class="md-list-item">
<div class="md-list-text">
{{ ... }}
</div>
</div>
</md-list-item>
</md-list>
I can’t find a way to match the generated div.md-list-item
from the component style.
Issue Analytics
- State:
- Created 7 years ago
- Comments:5 (1 by maintainers)
Top Results From Across the Web
Encapsulating Style and Structure with Shadow DOM
Custom properties can pierce the shadow boundary and effect content inside a shadow node. “Can we use a <link> element inside of a...
Read more >Using web components to encapsulate CSS and resolve ...
The solution: CSS encapsulation with web components Custom elements brought it all together. The top-level template loads source/javascripts/ ...
Read more >angular style not applied on components (despite the use of ...
I reckon it has something to do with the way angular displays the component since changing the tag to a DIV works. But...
Read more >Angular Styling Encapsulation Not Working - MDBootstrap
Expected behavior I'm sure I'm missing something being a newby to MDB, but I am unable to style elements of MDB within child...
Read more >CSS style not applying on dynamic injected html elements
I am using Angular 2.0.0-beta.12 & D3, i am injecting D3 barchart after viewInit, and inject css in component by adding attribute "styles", ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
You can get at them with either /deep/ or >>> (even though they are deprecated in CSS) angular supports them. see the page on styling on the angular.io site
But you can still use ::ng-deep