0

I have an Angular 13 app & a couple of components structure look as below

  1. logo component

    <svg enable-background="new 0 0 2014 1674.641" version="1.1" 
    viewBox="0 0 2014 1674.641" xml:space="preserve" xmlns="http://www.w3.org/2000/svg">
    </svg>
    
  2. header component

    <div class="appHeader">
       <a href="https://mysite"> 
         <app-logo> </app-logo>
       </a>
    

I'm trying to set the width & height of the svg (logo-component) from the header-component

header.component.css

  .appHeader svg 
   {
    width: 20rem;
    height: 3.5rem;
   }     

However, this way CSS intended for svg logo is not reflected. How can I apply CSS to such child component from its parent component?

Thanks!

1 Answer 1

2

Since component style are encapsulated by default. you should use ::ng-deep to disable view-encapsulation for that rule

::ng-deep .appHeader svg {
    width: 20rem;
    height: 3.5rem;
 }  
Sign up to request clarification or add additional context in comments.

5 Comments

ng-deep deprecated
@Murugan The shadow-piercing descendant combinator is deprecated and support is being removed from major browsers and tools. As such we plan to drop support in Angular (for all 3 of /deep/, >>>, and ::ng-deep). Until then ::ng-deep should be preferred for a broader compatibility with the tools.
As of angular 17 using ::ng-deep should be fine I guess

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.