Set tr or td width in HTML5

2

I need to set the width of a column to a table , but the width ( inline ) in HTML5 is not supported, as per the documentation: HTML Tag

In this case, can not be done inline ? What are the options?

As in email marketing, everything should be inline , and now!?

    
asked by anonymous 18.05.2018 / 13:31

2 answers

1

EDIT:

To do the direct style in the tag you can use style="" to put width

It will look like this:

<table border="1">
      <tr>
        <td style="width:100px">100px</td>
        <td style="width:200px">200px</td>
      </tr>
    </table>

RBZ I believe that in this link the source refers to the width direct in the type tag:

<td width="100px"> isso é errado mesmo!

Notice that all link attributes are properties of the <td> tag such as colspan , nowrap , align etc. This does not refer to width of CSS!

Words from Mozilla documentation: link

  

Usage Note: Do not use this attribute, as it has been deprecated. The rules should be defined and styled using CSS . Use the width property instead.

That is, use width for CSS. As in the example below.

.gg {
  width: 100px;
}
.ggg {
  width: 200px;
}
<table border="1">
  <tr>
    <td class="gg">100px</td>
    <td class="ggg">200px</td>
  </tr>
</table>
    
18.05.2018 / 13:49
2

Just an addendum, you'd prefer to take direct references to link or < br> link
are more reliable

Returning to your question, why not use css ? The width attribute is fully supported by the TD element. HTML5 does not encourage you to use these attributes in the tags, see the font element that has been deprecated, all this to focus on where it should be in CSS

See this example of how to use in CSS simply:

table { border-collapse: collapse;}
th, td { border: solid 1px; padding: 0 }
td:first-child { width: 200px  }
td:first-child + td {  width: 150px }
td:first-child + td + td {  width: 120px }
<table>
      <tr>
          <th>Primeira 200px</th>
          <th>Segunda 150px</th>
          <th>Terceira 120px</th>
      </tr>
      <tr>
          <td>texto</td>
          <td>texto</td>
          <td>texto</td>
      </tr>
  </table>

Note that I used the first-child + td selector to apply a different style for each td in sequence of the table.

    
18.05.2018 / 13:56