Component css styles are not applied?
See original GitHub issueIt appears that any css that I add to my component.css is not applied inside the markdown directive.
<markdown [data]="mydata">
<!-- component css ain't working in here -->
</markdown>
You can verify this by e.g. adding h2 {color: red } in the styles part near the top of app.ts in your plunker, https://plnkr.co/edit/y5LPj7?p=preview
@Component({
styles: [`
h2 { color: red; /* not working */
}
`],
})
Issue Analytics
- State:
- Created 6 years ago
- Reactions:5
- Comments:15 (2 by maintainers)
Top Results From Across the Web
CSS is not working in my angular component - Stack Overflow
The CSS classes in my rating.component.ts file are not working. My project is compiling because I can add text to my rating component...
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 >Component styles - Angular
Sometimes it's useful to apply styles to elements within a component's template based on some condition in an element that is an ancestor...
Read more >ASP.NET Core Blazor CSS isolation - Microsoft Learn
Isolate CSS styles to individual pages, views, and components to reduce or avoid: Dependencies on global styles that can be challenging to ...
Read more >Angular :host, :host-context, ::ng-deep - The Complete Guide
In this post, we will learn how the default Angular styling mechanism (Emulated Encapsulation) works under the hood, and we will also cover ......
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
Hi @ben4d85, thanks for bringing that up!
Right now this problem is due to the ViewEncapsulation of the components that uses the default
ViewEncapsulation.Emulated
which means that the CSS that is inside the component opening/closing tags is scoped.Workarounds
There is 2 workarounds you can use right now (that I tested in Plunker) …
Shadow-piercing
You can use the
::ng-deep
shadow-piercer in your CSS to force styling to be applied inside the scope of themarkdown
component.Plunker example: https://plnkr.co/edit/UdmGqrar9LmSJoUh?p=preview
Removing encapsulation on your component
Another way would be to remove the encapsulation of your component by using
ViewEncapsulation.None
which would make the CSS of this component global instead of scoped.Plunker example: https://plnkr.co/edit/Z5tsu5?p=preview
Long term solution
I will take a look in the next few days to see the impact of setting
ViewEncapsulation.None
onmarkdown
component so we don’t have to use any workaround to apply styling inside the component.I’ll keep the issue open until I investigate.
::ng-deep was the only solution that worked for me.
This was now properly applied within the markdown component.