tables.html 13.1 KB
Newer Older
Mark Otto's avatar
Mark Otto committed
1
2
3
4
5
<div class="bs-docs-section">
  <h1 id="tables" class="page-header">Tables</h1>

  <h2 id="tables-example">Basic example</h2>
  <p>For basic styling&mdash;light padding and only horizontal dividers&mdash;add the base class <code>.table</code> to any <code>&lt;table&gt;</code>. It may seem super redundant, but given the widespread use of tables for other plugins like calendars and date pickers, we've opted to isolate our custom table styles.</p>
6
  <div class="bs-example" data-example-id="simple-table">
Mark Otto's avatar
Mark Otto committed
7
    <table class="table">
8
      <caption>Optional table caption.</caption>
Mark Otto's avatar
Mark Otto committed
9
10
11
12
13
14
15
16
17
18
      <thead>
        <tr>
          <th>#</th>
          <th>First Name</th>
          <th>Last Name</th>
          <th>Username</th>
        </tr>
      </thead>
      <tbody>
        <tr>
Patrick H. Lauke's avatar
Patrick H. Lauke committed
19
          <th scope="row">1</th>
Mark Otto's avatar
Mark Otto committed
20
21
22
23
24
          <td>Mark</td>
          <td>Otto</td>
          <td>@mdo</td>
        </tr>
        <tr>
Patrick H. Lauke's avatar
Patrick H. Lauke committed
25
          <th scope="row">2</th>
Mark Otto's avatar
Mark Otto committed
26
27
28
29
30
          <td>Jacob</td>
          <td>Thornton</td>
          <td>@fat</td>
        </tr>
        <tr>
Patrick H. Lauke's avatar
Patrick H. Lauke committed
31
          <th scope="row">3</th>
Mark Otto's avatar
Mark Otto committed
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
          <td>Larry</td>
          <td>the Bird</td>
          <td>@twitter</td>
        </tr>
      </tbody>
    </table>
  </div><!-- /example -->
{% highlight html %}
<table class="table">
  ...
</table>
{% endhighlight %}


  <h2 id="tables-striped">Striped rows</h2>
  <p>Use <code>.table-striped</code> to add zebra-striping to any table row within the <code>&lt;tbody&gt;</code>.</p>
Chris Rebert's avatar
Chris Rebert committed
48
  <div class="bs-callout bs-callout-danger" id="callout-tables-striped-ie8">
Mark Otto's avatar
Mark Otto committed
49
50
51
    <h4>Cross-browser compatibility</h4>
    <p>Striped tables are styled via the <code>:nth-child</code> CSS selector, which is not available in Internet Explorer 8.</p>
  </div>
52
  <div class="bs-example" data-example-id="striped-table">
Mark Otto's avatar
Mark Otto committed
53
54
55
56
57
58
59
60
61
62
63
    <table class="table table-striped">
      <thead>
        <tr>
          <th>#</th>
          <th>First Name</th>
          <th>Last Name</th>
          <th>Username</th>
        </tr>
      </thead>
      <tbody>
        <tr>
Patrick H. Lauke's avatar
Patrick H. Lauke committed
64
          <th scope="row">1</th>
Mark Otto's avatar
Mark Otto committed
65
66
67
68
69
          <td>Mark</td>
          <td>Otto</td>
          <td>@mdo</td>
        </tr>
        <tr>
Patrick H. Lauke's avatar
Patrick H. Lauke committed
70
          <th scope="row">2</th>
Mark Otto's avatar
Mark Otto committed
71
72
73
74
75
          <td>Jacob</td>
          <td>Thornton</td>
          <td>@fat</td>
        </tr>
        <tr>
Patrick H. Lauke's avatar
Patrick H. Lauke committed
76
          <th scope="row">3</th>
Mark Otto's avatar
Mark Otto committed
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
          <td>Larry</td>
          <td>the Bird</td>
          <td>@twitter</td>
        </tr>
      </tbody>
    </table>
  </div><!-- /example -->
{% highlight html %}
<table class="table table-striped">
  ...
</table>
{% endhighlight %}


  <h2 id="tables-bordered">Bordered table</h2>
  <p>Add <code>.table-bordered</code> for borders on all sides of the table and cells.</p>
93
  <div class="bs-example" data-example-id="bordered-table">
Mark Otto's avatar
Mark Otto committed
94
95
96
97
98
99
100
101
102
103
104
    <table class="table table-bordered">
      <thead>
        <tr>
          <th>#</th>
          <th>First Name</th>
          <th>Last Name</th>
          <th>Username</th>
        </tr>
      </thead>
      <tbody>
        <tr>
Patrick H. Lauke's avatar
Patrick H. Lauke committed
105
          <th scope="row">1</th>
Mark Otto's avatar
Mark Otto committed
106
107
108
109
110
          <td>Mark</td>
          <td>Otto</td>
          <td>@mdo</td>
        </tr>
        <tr>
Patrick H. Lauke's avatar
Patrick H. Lauke committed
111
          <th scope="row">2</th>
Mark Otto's avatar
Mark Otto committed
112
113
114
115
116
          <td>Jacob</td>
          <td>Thornton</td>
          <td>@fat</td>
        </tr>
        <tr>
Patrick H. Lauke's avatar
Patrick H. Lauke committed
117
118
119
          <th scope="row">3</th>
          <td>Larry</td>
          <td>the Bird</td>
Mark Otto's avatar
Mark Otto committed
120
121
122
123
124
125
126
127
128
129
130
131
132
133
          <td>@twitter</td>
        </tr>
      </tbody>
    </table>
  </div><!-- /example -->
{% highlight html %}
<table class="table table-bordered">
  ...
</table>
{% endhighlight %}


  <h2 id="tables-hover-rows">Hover rows</h2>
  <p>Add <code>.table-hover</code> to enable a hover state on table rows within a <code>&lt;tbody&gt;</code>.</p>
134
  <div class="bs-example" data-example-id="hoverable-table">
Mark Otto's avatar
Mark Otto committed
135
136
137
138
139
140
141
142
143
144
145
    <table class="table table-hover">
      <thead>
        <tr>
          <th>#</th>
          <th>First Name</th>
          <th>Last Name</th>
          <th>Username</th>
        </tr>
      </thead>
      <tbody>
        <tr>
Patrick H. Lauke's avatar
Patrick H. Lauke committed
146
          <th scope="row">1</th>
Mark Otto's avatar
Mark Otto committed
147
148
149
150
151
          <td>Mark</td>
          <td>Otto</td>
          <td>@mdo</td>
        </tr>
        <tr>
Patrick H. Lauke's avatar
Patrick H. Lauke committed
152
          <th scope="row">2</th>
Mark Otto's avatar
Mark Otto committed
153
154
155
156
157
          <td>Jacob</td>
          <td>Thornton</td>
          <td>@fat</td>
        </tr>
        <tr>
Patrick H. Lauke's avatar
Patrick H. Lauke committed
158
159
160
          <th scope="row">3</th>
          <td>Larry</td>
          <td>the Bird</td>
Mark Otto's avatar
Mark Otto committed
161
162
163
164
165
166
167
168
169
170
171
172
173
174
          <td>@twitter</td>
        </tr>
      </tbody>
    </table>
  </div><!-- /example -->
{% highlight html %}
<table class="table table-hover">
  ...
</table>
{% endhighlight %}


  <h2 id="tables-condensed">Condensed table</h2>
  <p>Add <code>.table-condensed</code> to make tables more compact by cutting cell padding in half.</p>
175
  <div class="bs-example" data-example-id="condensed-table">
Mark Otto's avatar
Mark Otto committed
176
177
178
179
180
181
182
183
184
185
186
    <table class="table table-condensed">
      <thead>
        <tr>
          <th>#</th>
          <th>First Name</th>
          <th>Last Name</th>
          <th>Username</th>
        </tr>
      </thead>
      <tbody>
        <tr>
Patrick H. Lauke's avatar
Patrick H. Lauke committed
187
          <th scope="row">1</th>
Mark Otto's avatar
Mark Otto committed
188
189
190
191
192
          <td>Mark</td>
          <td>Otto</td>
          <td>@mdo</td>
        </tr>
        <tr>
Patrick H. Lauke's avatar
Patrick H. Lauke committed
193
          <th scope="row">2</th>
Mark Otto's avatar
Mark Otto committed
194
195
196
197
198
          <td>Jacob</td>
          <td>Thornton</td>
          <td>@fat</td>
        </tr>
        <tr>
Patrick H. Lauke's avatar
Patrick H. Lauke committed
199
          <th scope="row">3</th>
Mark Otto's avatar
Mark Otto committed
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
          <td colspan="2">Larry the Bird</td>
          <td>@twitter</td>
        </tr>
      </tbody>
    </table>
  </div><!-- /example -->
{% highlight html %}
<table class="table table-condensed">
  ...
</table>
{% endhighlight %}


  <h2 id="tables-contextual-classes">Contextual classes</h2>
  <p>Use contextual classes to color table rows or individual cells.</p>
  <div class="table-responsive">
    <table class="table table-bordered table-striped">
      <colgroup>
        <col class="col-xs-1">
        <col class="col-xs-7">
      </colgroup>
      <thead>
        <tr>
          <th>Class</th>
          <th>Description</th>
        </tr>
      </thead>
      <tbody>
        <tr>
Patrick H. Lauke's avatar
Patrick H. Lauke committed
229
          <th scope="row">
Mark Otto's avatar
Mark Otto committed
230
            <code>.active</code>
Patrick H. Lauke's avatar
Patrick H. Lauke committed
231
          </th>
Mark Otto's avatar
Mark Otto committed
232
233
234
          <td>Applies the hover color to a particular row or cell</td>
        </tr>
        <tr>
Patrick H. Lauke's avatar
Patrick H. Lauke committed
235
          <th scope="row">
Mark Otto's avatar
Mark Otto committed
236
            <code>.success</code>
Patrick H. Lauke's avatar
Patrick H. Lauke committed
237
          </th>
Mark Otto's avatar
Mark Otto committed
238
239
240
          <td>Indicates a successful or positive action</td>
        </tr>
        <tr>
Patrick H. Lauke's avatar
Patrick H. Lauke committed
241
          <th scope="row">
Mark Otto's avatar
Mark Otto committed
242
            <code>.info</code>
Patrick H. Lauke's avatar
Patrick H. Lauke committed
243
          </th>
Mark Otto's avatar
Mark Otto committed
244
245
246
          <td>Indicates a neutral informative change or action</td>
        </tr>
        <tr>
Patrick H. Lauke's avatar
Patrick H. Lauke committed
247
          <th scope="row">
Mark Otto's avatar
Mark Otto committed
248
            <code>.warning</code>
Patrick H. Lauke's avatar
Patrick H. Lauke committed
249
          </th>
Mark Otto's avatar
Mark Otto committed
250
251
252
          <td>Indicates a warning that might need attention</td>
        </tr>
        <tr>
Patrick H. Lauke's avatar
Patrick H. Lauke committed
253
          <th scope="row">
Mark Otto's avatar
Mark Otto committed
254
            <code>.danger</code>
Patrick H. Lauke's avatar
Patrick H. Lauke committed
255
          </th>
Mark Otto's avatar
Mark Otto committed
256
257
258
259
260
          <td>Indicates a dangerous or potentially negative action</td>
        </tr>
      </tbody>
    </table>
  </div>
261
  <div class="bs-example" data-example-id="contextual-table">
Mark Otto's avatar
Mark Otto committed
262
263
264
265
266
267
268
269
270
271
272
    <table class="table">
      <thead>
        <tr>
          <th>#</th>
          <th>Column heading</th>
          <th>Column heading</th>
          <th>Column heading</th>
        </tr>
      </thead>
      <tbody>
        <tr class="active">
Patrick H. Lauke's avatar
Patrick H. Lauke committed
273
          <th scope="row">1</th>
Mark Otto's avatar
Mark Otto committed
274
275
276
277
278
          <td>Column content</td>
          <td>Column content</td>
          <td>Column content</td>
        </tr>
        <tr>
Patrick H. Lauke's avatar
Patrick H. Lauke committed
279
          <th scope="row">2</th>
Mark Otto's avatar
Mark Otto committed
280
281
282
283
284
          <td>Column content</td>
          <td>Column content</td>
          <td>Column content</td>
        </tr>
        <tr class="success">
Patrick H. Lauke's avatar
Patrick H. Lauke committed
285
          <th scope="row">3</th>
Mark Otto's avatar
Mark Otto committed
286
287
288
289
290
          <td>Column content</td>
          <td>Column content</td>
          <td>Column content</td>
        </tr>
        <tr>
Patrick H. Lauke's avatar
Patrick H. Lauke committed
291
          <th scope="row">4</th>
Mark Otto's avatar
Mark Otto committed
292
293
294
295
296
          <td>Column content</td>
          <td>Column content</td>
          <td>Column content</td>
        </tr>
        <tr class="info">
Patrick H. Lauke's avatar
Patrick H. Lauke committed
297
          <th scope="row">5</th>
Mark Otto's avatar
Mark Otto committed
298
299
300
301
302
          <td>Column content</td>
          <td>Column content</td>
          <td>Column content</td>
        </tr>
        <tr>
Patrick H. Lauke's avatar
Patrick H. Lauke committed
303
          <th scope="row">6</th>
Mark Otto's avatar
Mark Otto committed
304
305
306
307
308
          <td>Column content</td>
          <td>Column content</td>
          <td>Column content</td>
        </tr>
        <tr class="warning">
Patrick H. Lauke's avatar
Patrick H. Lauke committed
309
          <th scope="row">7</th>
Mark Otto's avatar
Mark Otto committed
310
311
312
313
314
          <td>Column content</td>
          <td>Column content</td>
          <td>Column content</td>
        </tr>
        <tr>
Patrick H. Lauke's avatar
Patrick H. Lauke committed
315
          <th scope="row">8</th>
Mark Otto's avatar
Mark Otto committed
316
317
318
319
320
          <td>Column content</td>
          <td>Column content</td>
          <td>Column content</td>
        </tr>
        <tr class="danger">
Patrick H. Lauke's avatar
Patrick H. Lauke committed
321
          <th scope="row">9</th>
Mark Otto's avatar
Mark Otto committed
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
          <td>Column content</td>
          <td>Column content</td>
          <td>Column content</td>
        </tr>
      </tbody>
    </table>
  </div><!-- /example -->
{% highlight html %}
<!-- On rows -->
<tr class="active">...</tr>
<tr class="success">...</tr>
<tr class="warning">...</tr>
<tr class="danger">...</tr>
<tr class="info">...</tr>

<!-- On cells (`td` or `th`) -->
<tr>
  <td class="active">...</td>
  <td class="success">...</td>
  <td class="warning">...</td>
  <td class="danger">...</td>
  <td class="info">...</td>
</tr>
{% endhighlight %}
Chris Rebert's avatar
Chris Rebert committed
346
  <div class="bs-callout bs-callout-warning" id="callout-tables-context-accessibility">
347
    <h4>Conveying meaning to assistive technologies</h4>
348
    <p>Using color to add meaning to a table row or individual cell only provides a visual indication, which will not be conveyed to users of assistive technologies – such as screen readers. Ensure that information denoted by the color is either obvious from the content itself (the visible text in the relevant table row/cell), or is included through alternative means, such as additional text hidden with the <code>.sr-only</code> class.</p>
349
  </div>
Mark Otto's avatar
Mark Otto committed
350
351

  <h2 id="tables-responsive">Responsive tables</h2>
352
  <p>Create responsive tables by wrapping any <code>.table</code> in <code>.table-responsive</code> to make them scroll horizontally on small devices (under 768px). When viewing on anything larger than 768px wide, you will not see any difference in these tables.</p>
353

Chris Rebert's avatar
Chris Rebert committed
354
  <div class="bs-callout bs-callout-warning" id="callout-tables-responsive-ff-fieldset">
355
    <h4>Firefox and fieldsets</h4>
Mark Otto's avatar
clarify    
Mark Otto committed
356
    <p>Firefox has some awkward fieldset styling involving <code>width</code> that interferes with the responsive table. This cannot be overriden without a Firefox-specific hack that we <strong>don't</strong> provide in Bootstrap:</p>
357
358
{% highlight css %}
@-moz-document url-prefix() {
Mark Otto's avatar
clarify    
Mark Otto committed
359
  fieldset { display: table-cell; }
360
361
362
363
364
}
{% endhighlight %}
    <p>For more information, read <a href="http://stackoverflow.com/questions/17408815/fieldset-resizes-wrong-appears-to-have-unremovable-min-width-min-content/17863685#17863685">this Stack Overflow answer</a>.</p>
  </div>

365
  <div class="bs-example" data-example-id="simple-responsive-table">
Mark Otto's avatar
Mark Otto committed
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
    <div class="table-responsive">
      <table class="table">
        <thead>
          <tr>
            <th>#</th>
            <th>Table heading</th>
            <th>Table heading</th>
            <th>Table heading</th>
            <th>Table heading</th>
            <th>Table heading</th>
            <th>Table heading</th>
          </tr>
        </thead>
        <tbody>
          <tr>
Patrick H. Lauke's avatar
Patrick H. Lauke committed
381
            <th scope="row">1</th>
Mark Otto's avatar
Mark Otto committed
382
383
384
385
386
387
388
389
            <td>Table cell</td>
            <td>Table cell</td>
            <td>Table cell</td>
            <td>Table cell</td>
            <td>Table cell</td>
            <td>Table cell</td>
          </tr>
          <tr>
Patrick H. Lauke's avatar
Patrick H. Lauke committed
390
            <th scope="row">2</th>
Mark Otto's avatar
Mark Otto committed
391
392
393
394
395
396
397
398
            <td>Table cell</td>
            <td>Table cell</td>
            <td>Table cell</td>
            <td>Table cell</td>
            <td>Table cell</td>
            <td>Table cell</td>
          </tr>
          <tr>
Patrick H. Lauke's avatar
Patrick H. Lauke committed
399
            <th scope="row">3</th>
Mark Otto's avatar
Mark Otto committed
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
            <td>Table cell</td>
            <td>Table cell</td>
            <td>Table cell</td>
            <td>Table cell</td>
            <td>Table cell</td>
            <td>Table cell</td>
          </tr>
        </tbody>
      </table>
    </div><!-- /.table-responsive -->

    <div class="table-responsive">
      <table class="table table-bordered">
        <thead>
          <tr>
            <th>#</th>
            <th>Table heading</th>
            <th>Table heading</th>
            <th>Table heading</th>
            <th>Table heading</th>
            <th>Table heading</th>
            <th>Table heading</th>
          </tr>
        </thead>
        <tbody>
          <tr>
Patrick H. Lauke's avatar
Patrick H. Lauke committed
426
            <th scope="row">1</th>
Mark Otto's avatar
Mark Otto committed
427
428
429
430
431
432
433
434
            <td>Table cell</td>
            <td>Table cell</td>
            <td>Table cell</td>
            <td>Table cell</td>
            <td>Table cell</td>
            <td>Table cell</td>
          </tr>
          <tr>
Patrick H. Lauke's avatar
Patrick H. Lauke committed
435
            <th scope="row">2</th>
Mark Otto's avatar
Mark Otto committed
436
437
438
439
440
441
442
443
            <td>Table cell</td>
            <td>Table cell</td>
            <td>Table cell</td>
            <td>Table cell</td>
            <td>Table cell</td>
            <td>Table cell</td>
          </tr>
          <tr>
Patrick H. Lauke's avatar
Patrick H. Lauke committed
444
            <th scope="row">3</th>
Mark Otto's avatar
Mark Otto committed
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
            <td>Table cell</td>
            <td>Table cell</td>
            <td>Table cell</td>
            <td>Table cell</td>
            <td>Table cell</td>
            <td>Table cell</td>
          </tr>
        </tbody>
      </table>
    </div><!-- /.table-responsive -->
  </div><!-- /example -->
{% highlight html %}
<div class="table-responsive">
  <table class="table">
    ...
  </table>
</div>
{% endhighlight %}
</div>