3

I have many html tables and one of these are named as "table1". I want to give style to this table only. I used:

#table1 tr,th,td
  {

   border: 5px solid black;
  }

But when it executed, other table's td , tr, th style is setted same as #table1 's style.

How Can I give Style to particular table's td , tr, th only????

1 Answer 1

10

You need to specify the parent also for th and td

#table1 tr, #table1 th, #table1 td {
    /* ... */
}

otherwise you will apply that style to

  • #table1 tr (all tr inside #table1)
  • th (all th no matter where they are)
  • td (all td no matter where they are)

As a side note, on certain modern browser a :any pseudoclass is available (with -moz- and -webkit- prefixes) so as soon as it will be implemented more consistently you could write

#table1 :any(tr, th, td) {
   ...
}

useful to avoid the repetition.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.