Code2night
  • Home
  • Guest Posts
  • Tutorial
  • Languages
    • Angular
    • C
    • C#
    • HTML/CSS
    • Java
    • JavaScript
    • Node.js
    • Python
    • React
    • SQL Server
    • TypeScript
  • Post Blog
  • Tools
    • JSON Beautifier
    • HTML Beautifier
    • XML Beautifier
    • CSS Beautifier
    • JS Beautifier
    • PDF Editor
    • Word Counter
    • Base64 Encode/Decode
    • Diff Checker
    • JSON to CSV
    • Password Generator
  • Register
  • Login
  1. Home
  2. Blogpost

How to Apply css on child components in Angular

Date- Jan 16,2022

10136

Angular js Child Components

Parent Components and child components

So, starting from the beginning if we have to add css on any component element. We can put it directly in the component css. But when we want to apply css to child component and we place that in component css. You will notice no css is getting applied to child component. The main issue about this is that the scope of component css is limited to the component itself . So we will see how to make it work on child components.

Old way- previously we could have applied css on child components using the ::ng-deep shadow-piercing descendant combinator for that. 


:host(.test) ::ng-deep div.label {
  border: 1px solid red;
}

:host(.test) ::ng-deep div.value {
  border: 1px solid green;
}

But now a days this has been deprecated so this is not used anymore. So we will see how to do it other way

ViewEncapsulation.None

So, View Encapsulation in Angular is a strategy which  we use  that determines how angular hides (encapsulates) the styles defined in the component from reaching to the the other parts or componetns of the application. The following three strategies provided by the Angular to determine how styles are applied. So, we can use ViewEncapsulation.None on the parent component like you can check in this code sample

@Component({
  selector: 'app-log',
  templateUrl: './log.component.html',
  styleUrls: ['./log.component.css'],
  encapsulation: ViewEncapsulation.None
})

This, will allow the parent components css to be applied on the child components. After you add this on your component, you have to stop the project and run again and you will notice you css has been applied on child components.

So, this is how we can apply css on child components in Angular js.

S
Shubham Batra
Programming author at Code2Night โ€” sharing tutorials on ASP.NET, C#, and more.
View all posts โ†’

Related Articles

Tag or mention people like WhatsApp & Skype by using @ in Angular
Jan 16, 2022
How to reload child components in vue.js
May 15, 2021

Comments

Tags

AspNet
C#
programming
AspNet MVC
c programming
AspNet Core
C
software development
tutorial
MVC
memory management
Paypal
coding
coding best practices
data structures
programming tutorial
tutorials
object oriented programming
Slick Slider
StripeNet
Free Download for Youtube Subscribers!

First click on Subscribe Now and then subscribe the channel and come back here.
Then Click on "Verify and Download" button for download link

Subscribe Now | 1760
Download
Support Us....!

Please Subscribe to support us

Thank you for Downloading....!

Please Subscribe to support us

Continue with Downloading
Be a Member
Join Us On Whatsapp Join Us On Facebook
Code2Night

A community platform for sharing programming knowledge, tutorials, and blogs. Learn, write, and grow with developers worldwide.

Panipat, Haryana, India
info@code2night.com
Quick Links
  • Home
  • Blogs
  • Tutorials
  • About Us
  • Contact
  • Privacy Policy
  • Terms & Conditions
  • Guest Posts
Free Dev Tools
  • JSON Beautifier
  • HTML Beautifier
  • CSS Beautifier
  • JS Beautifier
  • Password Generator
  • QR Code Generator
  • Hash Generator
  • Diff Checker
  • Base64 Encode/Decode
  • Word Counter
By Language
  • Angular
  • C
  • C#
  • HTML/CSS
  • Java
  • JavaScript
  • Node.js
  • Python
  • React
  • SQL Server
  • TypeScript
© 2026 Code2Night. All Rights Reserved.
Made with for developers  |  Privacy  ยท  Terms
Translate Page