Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<h1>Specificity</h1> <p>Your issue is most likely regarding specificity. Chris Coyier has a great article on <a href="http://css-tricks.com/specifics-on-css-specificity/">CSS specificity</a>. I would also suggest you check out this handy <a href="http://specificity.keegan.st/">specificity calculator</a>.</p> <p>Using that calculator, we can see that <code>.table-striped &gt; tbody &gt; tr:nth-child(odd) &gt; td</code> has a specificity of 23. As such, to override that, any new rule needs to have a specificity of something equal to or greater than 23. <code>.red</code> is at 10, so that isn't going to cut it.</p> <p>In this case, it should be as simple as matching the existing specificity, and then adding your class to it. <code>.table-striped &gt; tbody &gt; tr:nth-child(odd) &gt; td.red</code> gives us a specificity of 33. As 33 is greater than 23, your rule should now work.</p> <p>See a working example here: <a href="http://bootply.com/91756">http://bootply.com/91756</a></p> <h1>!important</h1> <p>In general, you should never use <code>!important</code> unless you never want that rule to be overridden. <code>!important</code> is basically the nuclear option. I am moderately confident in saying that if you understand specificity, you should never need to <code>!important</code> to make a custom rule work properly in a framework like Bootstrap.</p> <h3>Update</h3> <p>After a bit of thought, the rule I provide here is probably a bit too specific. What happens if you want to higlight a cell on a table that isn't stripped? To make your rule a bit more global while still having enough specificity to work in stripped tables, I would go with <code>.table &gt; tbody &gt; tr &gt; td.red</code>. This has the same specificity as the Bootstrap stripping, but will also work on tables that are not zebra stripped. Updated example is here: <a href="http://bootply.com/91760">http://bootply.com/91760</a></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload