1

I'm trying to change the padding on mat-cell and I've noticed some weird behavior. If I write the css inside the component's css file everything works just fine, but if I write it in style.css (I want to apply it to the whole app) it gets overwritten by the default.

I guess this has to do with the order in which the css files are applied. If that is the case, how can I see this order and is there a way to change it or bring style.css on top?

2
  • 2
    Have you tried with "!important"? Commented Oct 29, 2020 at 11:36
  • "!important" fixes the problem, but that won't allow it to be further overwritten in certain components, and I'm trying to avoid that. Commented Oct 29, 2020 at 15:48

3 Answers 3

3

I would suggest to create a separate .scss file reserved for styling globaly Angular Material elements, and importing it in the main styles.scss file. Answering your question - propably you're not 'specific' enough. First of all it would be nice to add an additional custom class to your Material element so the custom styles will be applied only when this class is present. Example on styling

.mat-table.my-custom-class {
   width: 100%;

   .mat-cell {
     font-size: 20px;
     padding: 20px;
   }
}

You might nest the elements event more for higher css specificity

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

Comments

0

That works for me:

.mat-cell {
  padding: 12px!important;
}

Comments

0

Check for the parent scope of default style which is overriding css added in style.css using developer tool. Use the same parental scope along with !important.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.