Bold "b" does not apply in a range

4

In table , if I apply bold ( <b> ) out of cells ( <td> ), it does not work:

<table>
  <tr>
    <b>
    <td>Cell A</td>
    <td>Cell B</td>
    <td>Cell C</td>
    <td>Cell D</td>
    </b>
  </tr>
</table>



If you apply inside, (obvious) it works, but I have to put in all you want:

    <table>
      <tr>
        <td><b>Cell A</b></td>
        <td>Cell B</td>
        <td><b>Cell C</b></td>
        <td>Cell D</td>
      </tr>
    </table>
  • Why does this occur?
  • The only way would be put manually in each cell, or CSS ?
  • Does it work in range of other tag types ?
asked by anonymous 13.08.2018 / 14:46

2 answers

5

According to the living standard of element Table only the The following elements can be used with 'children':

This is because the element is intended to display tabular data, not formatting. To do this, use CSS:

td.bold {font-weight:bold;}
<table>
  <tr>
    <td class='bold'>Cell A</td>
    <td>Cell B</td>
    <td class='bold'>Cell C</td>
    <td>Cell D</td>
  </tr>
</table>
    
13.08.2018 / 15:07
3

"Why does this occur?"

Because a TD element must next come from a TR element, there is no space for elements between them.

"The only way would be to manually put in each cell, or by CSS?"

Yes, in every TD (horrible), or using CSS, hence it can be a class or applying directly from TR also, that would work in your case

"Does it work in range of other types of tags?"

Yes, it may be within DIV for example, and affect all elements then, but the <B> tag is discontinued, it is considered obsolete ( read more here ) and therefore recommended to use the CSS attribute for this, font-weight: bold

tr {
  font-weight: bold
}

Here's just an example, best to apply a class otherwise all lines will be bold, or if it's a title use TH

    

13.08.2018 / 15:01