Is there anything built into to Twitter Bootstrap 2.0 to align table contents?
Asked Answered
M

3

23

It is easy to align table by setting "align" attribute, but table aligning by css is a bit hacky. Is there built-in support for tables aligning in Twitter Bootstrap 2.0?

Martyry answered 23/6, 2012 at 11:50 Comment(1)
I'm not sure this is 'hacky'. Bootstrap is just that a bootstrap to get things started and is meant to be built upon.Freitas
F
24

There is nothing built in to support this but it is very easy to add something like:

.table th.rightCell,
.table td.rightCell {
  text-align: right;
}
Freitas answered 29/10, 2012 at 10:40 Comment(1)
Alternatively to keep Bootstrap's naming conventions and to utilize the pre-built text-right class, you should add this to your own css: .table th.text-right, .table td.text-right { text-align: right; } and then use <td class="text-right">Ta-dam</td>Amethyst
G
12

Bootstrap's alignment classes include .text-right which sets text-align: right.

Unfortunately Bootstrap sets text-align: left for table cells so applying .text-right to a <td> doesn't have any effect:

<td class="text-right">
  Still left aligned
</td>

Adding .text-right to a block element inside the cell however does work:

<td>
  <p class="text-right">Right aligned</p>
</td>
<td>
  <div class="text-right">Right aligned</div>
</td>
Gilliam answered 27/3, 2013 at 15:6 Comment(1)
I'm using Bootstrap 3.0, and .text-right works perfectly when applied directly to a <td>.Paralytic
G
0

For "td" I used this which is included in bootstrap css:

<td class="pagination-centered">
Graves answered 3/11, 2012 at 13:18 Comment(1)
"pagination-centered" <- it's too long (19 chars). I'd rather use a shorter classnames.Rocha

© 2022 - 2024 — McMap. All rights reserved.