2

I have a generic .modal-content set in styles.css. This applies to every modal panel in the application. I would like to override its width in the component.css. This component has also a modal panel, and even if I put the following into the component.css, the modal will retain its global width.

.modal-content{
  border-radius: 0;
  border:none;
  width: 25%;
}

Even if I use !important it does not have any effect.

What can I do to override the global css value?

EDIT

@Component({
  selector: 'app-base-data',
  templateUrl: './base-data.component.html',
  styleUrls: ['./base-data.component.css']
})
export class BaseDataComponent implements OnInit {
5
  • Could you also post your component html and ts? What view encapsulation strategy are you using? Commented Mar 20, 2019 at 17:00
  • 3
    you can set encapsulation: ViewEncapsulation.None in the component Commented Mar 20, 2019 at 17:03
  • Would advice that turning ViewEncapsulation off might cause more issues as well Commented Mar 20, 2019 at 17:07
  • @JoelJoseph it works. make it an answer. and I'll accept it. Commented Mar 20, 2019 at 17:10
  • @Sanyifejű done Commented Mar 20, 2019 at 17:23

1 Answer 1

9

To override global style rule on the component style file, add this on your component.ts

encapsulation: ViewEncapsulation.None

check out the official doc : https://angular.io/api/core/ViewEncapsulation

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

2 Comments

but this will leak the component.css to the rest of the application :(
I get the desired effect without leaking to other components using encapsulation: ViewEncapsulation.ShadowDom

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.