Search code examples
cssmediawikicss-specificity

Override CSS !important


A CMS is automatically adding .content table {width:auto!important} to all my pages. (MediaWiki with the MobileFrontend extension and the site in mobile view)

The problem is, there are some tables I'd like to make 100%, but I also don't want to edit any of the CMS's code.

I can add my own CSS and used .mytableclassname {width:100%} and .mytableclassname {width:100%!important} both of which didn't set my table at 100%.

I can add .content table {width:100%!important} which now makes mytableclassname at 100%, but also every other table at 100% width too.

Is there a way to set .content table {width:} to something neutral to remove the forced auto size, and then set .mytableclassname {width:100%}?

I don't want to use any ids since there could be multiple tables on the same page.


Solution

  • that's a specifity issue. Use

    .content table.mytableclassname {width:100% !important}
    

    to override the default rule. Simply said, that has more "weight" (i.e. higher specifity) than any of the rules you listed in your question.