Select all tables with a given class and apply a class to the firt cell and another one to the second cell.

Hello,
I am working on a html document and I have the following tables


<table class="titles">
        <tr>
            <td class="cells">Nom de l'assuré</td>
            <td class="content">{{#childtable.place.rows}}{{fields.name}}{{/childtable.place.rows}}</td>
        </tr>
        <tr>
            <td class="cells">Lieu du sinistre</td>
            <td class="content">{{#childtable.address_view.rows}}{{fields.address}}&nbsp;-&nbsp;{{fields.second_address}}{{/childtable.address_view.rows}}</td>
        </tr>
        <tr>
            <td class="cells">Adresse de l'assuré</td>
            <td class="content">{{#childtable.address_view.rows}}{{fields.address}}&nbsp;-&nbsp;{{fields.second_address}}{{/childtable.address_view.rows}}</td>
        </tr>
        <tr>
            <td class="cells">N° de dossier</td>
            <td class="content">{{#childtable.request.rows}}{{fields.user_def16}}{{/childtable.request.rows}}</td>
        </tr>
    </table>
With the following CSS:
.titles{
            border-left: solid grey;
            border-width: thick;
            border-collapse: collapse;
        }

        .cells{
            font-weight: bold;
            background-color: lightgrey;
            padding-left: 3px;
            width: 25%;
        }
        .content{
            background-color: paleturquoise;
            width: 75%;
            padding-left: 3px;
            border: solid thin black;
            border-width: 0px 0px 1px 1px;
        }


Since I have a lot fof tables with taht layout, and I want to avoid to put the class .cells and the class .content to all the cells of the table, I would like a css code that can select all tables that have the class "titles" and apply them the class.

Thank youPreview
Alain BensimonAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jan LouwerensSoftware EngineerCommented:
CSS cannot apply classes to markup. You can only style what's already there.

But, if I'm understanding your question correctly, you don't need to add classes. You can do what you want with pure CSS:
<style>
.titles tr td:nth-child(1) {
   font-weight: bold;
   background-color: lightgrey;
   padding-left: 3px;
   width: 25%;
}
.titles tr td:nth-child(2) {
   background-color: paleturquoise;
   width: 75%;
   padding-left: 3px;
   border: solid thin black;
   border-width: 0px 0px 1px 1px;
}
</style>

<table class="titles">
   <tr>
      <td>Nom de l'assuré</td>
      <td>{{#childtable.place.rows}}{{fields.name}}{{/childtable.place.rows}}</td>
   </tr>
   <tr>
      <td>Lieu du sinistre</td>
      <td>{{#childtable.address_view.rows}}{{fields.address}}&nbsp;-&nbsp;{{fields.second_address}}{{/childtable.address_view.rows}}</td>
   </tr>
   <tr>
      <td>Adresse de l'assuré</td>
      <td>{{#childtable.address_view.rows}}{{fields.address}}&nbsp;-&nbsp;{{fields.second_address}}{{/childtable.address_view.rows}}</td>
   </tr>
   <tr>
      <td>N° de dossier</td>
      <td>{{#childtable.request.rows}}{{fields.user_def16}}{{/childtable.request.rows}}</td>
   </tr>
</table>

Open in new window

1

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Alain BensimonAuthor Commented:
Thank you.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
CSS

From novice to tech pro — start learning today.