user3112668
user3112668

Reputation:

How can I edit color, font, bg_color of specific cells in my table using css

I have a simple html table and have been trying to change the fonts and colours of specific cells but cant seem to do it.

Here is my table, all I have for my css on this table is shown.

 table,
 th,
 td {
   border: solid;
   font-family: Mylius;
   font-size: 12px;
 }
<table>
  <td colspan="3">Baggage allowance</td>
  <colgroup>
    <col width="800px">
  </colgroup>
  <tr>
    <td>Passenger</td>
    <td>Total</td>
  </tr>
  <tr>
    <td>Test adult</td>
    <td>46kg</td>
  </tr>
  <colgroup>
    <col width="450px">
  </colgroup>
  <tr>
    <td>Test infant</td>
    <td>23kg</td>
  </tr>
  <tr>
    <td colspan="3">All baggage should have handles</td>
  </tr>
</table>

Upvotes: 0

Views: 584

Answers (3)

Thomas Marstrander
Thomas Marstrander

Reputation: 46

A simple google search for css styles should explain this to you. You should do a more thorough effort before asking questions. Anyway here is the basics:

You can set the style inline directly on the cell:

<td bgcolor="#FF00FF" style="font-family:courier">Test adult</td>

Or set a class on the specific cells you want to change and create a css rule.

<td class="red">Test adult</td>

and put the following inside your css file:

td.red {
  background: red
}

Upvotes: 1

Nicole Cook
Nicole Cook

Reputation: 314

There is an example of what you are trying to do here: http://www.techrepublic.com/article/why-css-styling-is-for-tables-too/

Upvotes: 0

Angel Perez
Angel Perez

Reputation: 11

Make changes inline. Like this:

<table>
  <tr>
    <td bgcolor="#FF0000">January</td>
    <td bgcolor="#00FF00">$100</td>
  </tr>
</table>

Upvotes: 0

Related Questions