0

I have 2 file theme.css and main.css

theme.css

.table td {
           border-top: 1px solid #e8edf1;
           vertical-align: top;
           padding: 5px 5px !important;
           color: #576475;
           font-size: 11px;
}

main.css

.table td {
            padding: 1px 2px;
 }

I want to override property of td via main.css by including main.css after theme.css.

But final output takes property of theme.css .

PS: I want to override only padding property.

2
  • 1
    add padding: 1px 2px !important; Commented Jan 9, 2017 at 11:14
  • Not directly related to the problem, but I'd expect a main.css to come before theme.css, because the first sounds more generic and a theme is something easily replaceable. Commented Jan 9, 2017 at 11:16

3 Answers 3

2

Since the first CSS rules has !important applied, the only way to override it is using another !important rule:

.table td {
    padding: 1px 2px !important;
}

If you can, remove the !important keyword from all your CSS. There's better ways of defining the order.

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

Comments

2

In terms of specificty, !important wins every time.

You should really avoid using !important and use specifity to your advantage. Ordering CSS files is one way to do it, ordering your rules is another.

For more on specificity: CSS-Tricks

So, in your case, you should remove the !important flag from your theme.css file, and that would solve it.

Comments

0

@Abhishek Please check following code with example of two different tables as per your requirement.

table td {
           border-top: 1px solid #e8edf1;
           vertical-align: top;
           padding: 5px 5px !important;
           color: #576475;
           font-size: 11px;
}

table.custom_table td{
  padding: 1px 2px !important;
 }
<table>
        <tr>  
            <td>fdhf</td>
             <td>dfdfdf</td>
          </tr>
              
  
</table>
<table class="custom_table">
        <tr>  
            <td>fdhf</td>
             <td>dfdfdf</td>
          </tr>
              
  
</table>

1 Comment

This reads more like a game of spot-the-difference than an answer. What did you change? Why does it solve the problem?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.