0

I tried to overwrite the css of a custom component selector but it is not working. I have tried :ng-deep without success. How do I find a solution for this?

app.component.html:

<mycustommcomp></mycustommcomp>

app.component.css:

::ng-deep mycustommcomp{ 
margin:2px;
overflow:unset !important; 
}

mycustomcomp.component.css:

mycustommcomp{ 
margin:8px;
overflow:hidden !important; 
}

Demo: https://stackblitz.com/edit/angular-vsdzqs?file=src/app/app.component.css

1 Answer 1

1

You cannot do this as style cannot be applied to component tags. One way to make it works is to wrap the content inside mycustommcomp with a container (such as div).

mycustommcomp.component.html:

<div class="container">
   <!--Content here-->
</div>

app.component.css:

::ng-deep .container{ 
   margin:2px;
   overflow:unset !important; 
}

mycustomcomp.component.css:

.container{ 
   margin:8px;
   overflow:hidden !important; 
}

Nevertheless please avoid doing this as ::ng-deep is deprecated.

Sign up to request clarification or add additional context in comments.

1 Comment

Do not use class.i want to overwrite the selector mycustommcomp css

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.