I am using Material 2 <md-input-container>
in my Angular component. I want to override one of the classes e.g. .mat-input-wrapper
defined in Angular Material. But I want to override only in that component and the override should not effect other components in the page.
Here is the screenshot of the rendered element:
To override, take the selector by inspecting the HTML element in your browser, and override the property you want. If it still fails, you can use ! important to force the style to be applied.
If you want to override a component's styles using custom classes, you can use the className prop, available on each component.
While Angular Material does not support defining custom styles or CSS overrides on components' internal elements, you might choose to do this anyway. There are three points to consider while customizing styles for Angular Material components: view encapsulation, CSS specificity, and rendering location.
The problem with ::ng-deep
is, it will apply the style across all the pages and all the components. Meaning its a dirty approach. A better way to do this, is to wrap with a custom class and style the element in your styles.scss/styles.css
Example:
As asked in the question. To override a .mat-input-wrapper
, wrap your element with your custom class like:
<md-input-container class='big-input'>
. Then in
styles.scss:
.big-input .mat-input-wrapper {
height : 200px;
}
add !important
if necessary.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With