rauschma,
@rauschma@fosstodon.org avatar

: I’m experimenting with aligning table columns. Maybe:

<table>
<style>
th:nth-child(1), td:nth-child(1) {
text-align: left;
}
th:nth-child(2), td:nth-child(2) {
text-align: right;
}
th:nth-child(3), td:nth-child(3) {
text-align: center;
}
</style>
<thead>
<th>Left</th><th>Right</th><th>Center</th>
</thead>
<tbody>
<tr>
<td>1A</td><td>1B</td><td>1C</td>
</tr>
<tr>
<td>2A</td><td>2B</td><td>2C</td>
</tr>
</tbody>
</table>

rauschma,
@rauschma@fosstodon.org avatar

Sadly, there doesn’t seem to be a better built-in way to align HTML table columns. There is the <col> element but its align attribute is deprecated.
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/col

tomw,
@tomw@mastodon.social avatar

@rauschma In any situation where the table is being produced by code, it's usually easy enough to add <td class="col1"> etc or even <td class="align-right"> as relevant. I realise that's a bit tightly coupled but so is the nth-child way...

  • All
  • Subscribed
  • Moderated
  • Favorites
  • webdev
  • rosin
  • thenastyranch
  • ethstaker
  • osvaldo12
  • mdbf
  • DreamBathrooms
  • InstantRegret
  • magazineikmin
  • Youngstown
  • ngwrru68w68
  • slotface
  • GTA5RPClips
  • kavyap
  • cubers
  • JUstTest
  • everett
  • cisconetworking
  • tacticalgear
  • anitta
  • khanakhh
  • normalnudes
  • Durango
  • modclub
  • tester
  • provamag3
  • Leos
  • megavids
  • lostlight
  • All magazines