I want to apply styles only to the table inside the DIV with a particular class:
Note: I’d rather use a css-selector for children elements.
Why does the #1 works and #2 doesn’t?
1:
div.test th, div.test td, div.test caption {padding:40px 100px 40px 50px;}
2:
div.test th, td, caption {padding:40px 100px 40px 50px;}
HTML:
<html> <head> <style> div.test > th, td, caption {padding:40px 100px 40px 50px;} </style> </head> <body> <div> <table border='2'> <tr><td>some</td></tr> <tr><td>data</td></tr> <tr><td>here</td></tr> </table> </div> <div class='test'> <table border='2'> <tr><td>some</td></tr> <tr><td>data</td></tr> <tr><td>here</td></tr> </table> </div> </body> </html>
What am I doing wrong?
This code ‘
div.test th, td, caption {padding:40px 100px 40px 50px;}‘ applies a rule to allthelements which are contained by adivelement with a class namedtest, in addition to alltdelements and allcaptionelements.It is not the same as ‘all
td,thandcaptionelements which are contained by adivelement with a class oftest‘. To accomplish that you need to change your selectors:‘
>‘ isn’t fully supported by some older browsers (I’m looking at you, Internet Explorer).