0

This particular html code is to create the table, with two rows, two columns and to decorate the first column back ground to red and to align second columns text to right. The very interesting thing encountered is the alignment is not happening why?

<table>
  <colgroup>
    <col style="background-color:red">
    <col style="text-align:right">
  </colgroup>
  <tr>
    <th>ISBN</th>
    <th>Title</th>
  </tr>
  <tr>
    <td>3476896</td>
    <td>My first HTML</td>
  </tr>
</table>
vidyakumargv
  • 953
  • 8
  • 12

2 Answers2

0

Jsfiddle DEMO

body > table > tbody > tr > th
{
    text-align:right;
}

you need to specify th tag for table header

Mehmet Eren Yener
  • 2,006
  • 1
  • 23
  • 37
0

Use nth-child instead. As the question in the comment mentions, text-align does not apply to col or colgroup tag.

http://jsfiddle.net/f2ue4/1/

td:nth-child(2),
th:nth-child(2) {
    text-align: right;
}
Huangism
  • 16,278
  • 7
  • 48
  • 74