Angular 2 emphasizes modularity by implementing a css scope in component styles to prevent parent component styles from affecting child components. This is why you see the attribute _ngcontent-c0
in all your components.
When you inspect the generated css for your component, you will find that the tag h1[_ngcontent-c0]
has been added to all styles.
Therefore, your Home and Carousel components should have their own unique styles:
@Component({
selector: 'home',
template: `<body>
<carousel></carousel>
</body>`,
styles: ['body { background-color: gray; }']
})
@Component({
selector: 'carousel',
template: `<div id="carousel_body">
<!-- carousel stuff here -->
</div>`,
styles: ['#carousel_body{ background-color: blue; }']
})
Other options include:
Using global styles by placing them in a css file referenced in index.html traditionally
Utilizing special selectors like :host or /deep/ to override css scoping mechanism (/deep/ is deprecated)
Disabling css scoping by setting
encapsulation: ViewEncapsulation.None
on all components, but this may compromise Angular's core benefits.
For more information on these options, visit here
Check out an example on plunkr here