Jump to content

Wish to use the same table at all times but differant border colours


Recommended Posts

Only new to css so please excuse if this is an easy question -

 

I am programming a game that displays your character on the right of the screen; I have set this up so it works fine in css.

 

I now wish to have all the borders set to a different colour depending on how healthy your character is, my css code is

TABLE.RightTable
{
  float:center;
  border-collapse:collapse;
  border:3px Solid Green;
  border-style:ridge;
}
TABLE.RightTable th {text-align:center; font-size:large; border:3px Solid Green; border-style:ridge;}
TABLE.RightTable td {font-size:normal; border:3px Solid Green; border-style:ridge;}

TABLE.RightTableBad
{
  float:center;
  border-collapse:collapse;
  border:3px Solid Red;
  border-style:ridge;
}
TABLE.RightTableBad th {text-align:center; font-size:large; border:3px Solid Red; border-style:ridge;}
TABLE.RightTableBad td {font-size:normal; border:3px Solid Red; border-style:ridge;}

 

As you can see the only difference is the colour of the border, is there a way of simplifying this code so I only have to call the css code once for all borders?  I would like to have more options (green if poisoned for example) but don't really wish to write out the css code again.

 

James

You can define multiple classes separated by a comma and then separately define any changes:

 

TABLE.RightTable,
TABLE.RightTableBad
{
  float:center;
  border-collapse:collapse;
  border:3px Solid Green;
  border-style:ridge;
}
TABLE.RightTable th,
TABLE.RightTableBad th
{text-align:center; font-size:large; border:3px Solid Green; border-style:ridge;}
TABLE.RightTable td,
TABLE.RightTableBad td
{font-size:normal; border:3px Solid Green; border-style:ridge;}

TABLE.RightTableBad
{
  border:3px Solid Red;
}
TABLE.RightTableBad th {border:3px Solid Red;}
TABLE.RightTableBad td {border:3px Solid Red;}

 

OR, make an additional class that just handles color.  You can apply multiple styles to an element, just separate them by a space:

 

<style>
  TABLE.RightTable { ... }
  .Bad td, Bad.th { border: 3px Solid Red; }
  ...
</style>
<table class="RightTable Bad">...</table>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.