Using CSS alongside Angular works smoothly.
Angular handles the CSS for the specific component you are working on, eliminating any need for concern on your end. This is achieved through shadow DOM functionality, which not all browsers support. In response, Angular mimics this behavior by adding properties to your components like so:
<div _ngcontent-c6>... your content ...</div>
Angular then transforms the original CSS code you wrote to something like this:
div[_ngcontent-c0] {
color: red; // for example
}
If you want to write CSS that affects other components beyond the current one, you can set the view encapsulation to none:
@Component({
selector: '...',
templateUrl: '',
styleUrls: [''],
encapsulation: ViewEncapsulation.none
})
Alternatively, in an Angular CLI project, you have the option to define global styles in a styles.scss
(or .css
) file that does not enforce view encapsulation.
Learn more at: https://angular.io/guide/component-styles#view-encapsulation
(Before disabling this feature, carefully consider its usefulness)