GibboK
GibboK

Reputation: 73918

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></table>
    </div>

    .Role
    {
    // Style for <table> tag.
    }

Upvotes: 0

Views: 140

Answers (6)

Tomas
Tomas

Reputation: 59483

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.)

Upvotes: 0

Eineki
Eineki

Reputation: 14909

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

Upvotes: 1

Fr&#233;d&#233;ric Hamidi
Fr&#233;d&#233;ric Hamidi

Reputation: 262939

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.
}

Upvotes: 2

Vinh C
Vinh C

Reputation: 438

To style the table in div with role class you need

.Role table {
  //style for table tag
}

Upvotes: 2

Rafael Vega
Rafael Vega

Reputation: 4645

.role > table {
    /* styles here */
}

Upvotes: 2

Delan Azabani
Delan Azabani

Reputation: 81384

You could use the .Role table selector.

Upvotes: 1

Related Questions