Is it possible to apply a HTML attribute to a Div Tag in CSS?
Hi I have a generic DIV with a Css Role applied.
I would like to know if CSS allows to set the style for an HTML Tag inside a DIV (only for DIV with that Role) which has a Css Role.
Please let me know your thoughts. Thanks for your time on this.
<div class="Role">
<table><开发者_StackOverflow/table>
</div>
.Role
{
// Style for <table> tag.
}
.role > table {
/* styles here */
}
To style the table in div with role class you need
.Role table {
//style for table tag
}
It is indeed possible, either with a descendant selector:
.Role table {
// Style for <table> element.
}
Or with a child selector:
.Role > table {
// Style for <table> element.
}
You have several options to go:
The descendant selector selector
.Role table
, for example, select for apply all the table that are contained into an element, whatever, with class Role.The child selector
.Role > table
will apply the associated rules to the tables that are child (not descendant) of the element with class Role
For example, consider this html fragment:
<div class="Role">
<table id="t1">
<tr><td>
<table id="t2">
....
</table>
</td></tr>
</table>
</div>
- .Role table will apply the css rule to table#t1 and table#t2
- .Role > table will apply the css rule to table#t1 only
- .Role > table table will apply the rule to table#t2 skipping to table#t1
You could use the .Role table
selector.
Just see the CSS selectors - pattern matching. You can use one of the following, depends on your needs:
.Role * { ... } /* matches any tag in div class="Role" */
.Role > * { ... } /* matches any tag which is direct child of div class="Role" */
You can replace * with any particular selector (tag, class, etc.)
精彩评论