How can I specify css for all td tags of a table of a certain class? I tried this:
.myclass td {padding: 1px;}
But it doesn't work. The html is:
<table class="myclass"><tr><td>foo
Your example should work. Double check:
- Case (ie: .myclass is not the same as .myClass)
- That the styling is valid for a Table Cell
Here's a working example: http://pastehtml.com/view/b2oxzzdp4.html
Try this
.myclass tr td {padding: 1px;}
Although it should work the same.
You may need to add more than 1px
of padding to see a difference. Perhaps it is working and you cannot see the change.
table.myclass td
{
padding: 1px;
}
Strange, I believe it should work. Check browser console for any errors.
And you can use for table cell padding table
attribute cellpadding
<table cellpadding="1">
</table>
You aren't closing your tags. Other than that, it works.
To answer your actual question, you specify CSS for a <td>
tag of a table of a certain class just like you did it in your question:
.myclass td { /* whatever */ }
Whether that CSS is what you want is another story.
If you have other items that share that class, and you want to make sure it's a table specifically, you can do this:
table.myclass td { /* whatever */ }
精彩评论