Skip to content

Instantly share code, notes, and snippets.

@sanketmaru
Last active June 6, 2019 10:03
Show Gist options
  • Save sanketmaru/511e0dad7bfb7a1cd7d311c5d98db859 to your computer and use it in GitHub Desktop.
Save sanketmaru/511e0dad7bfb7a1cd7d311c5d98db859 to your computer and use it in GitHub Desktop.
Notes on Component Styling in Angular

The :host selector is the only way to target the host element. You can't reach the host element from inside the component with other selectors because it's not part of the component's own template.

:host(.active) {
  border-width: 3px;
}

The :host-context() selector looks for a CSS class in any ancestor of the component host element, up to the document root.

:host-context(.theme-light) h2 {
  background-color: #eef;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment