mirror of
https://github.com/mdbootstrap/mdb-ui-kit.git
synced 2024-11-15 06:08:57 +03:00
685 lines
15 KiB
Markdown
Executable File
685 lines
15 KiB
Markdown
Executable File
---
|
|
layout: docs
|
|
title: Tables
|
|
description: Documentation and examples for opt-in styling of tables (given their prevelant use in JavaScript plugins) with Bootstrap.
|
|
group: content
|
|
toc: true
|
|
---
|
|
|
|
## Examples
|
|
|
|
Due to the widespread use of tables across third-party widgets like calendars and date pickers, we've designed our tables to be **opt-in**. Just add the base class `.table` to any `<table>`, then extend with custom styles or our various included modifier classes.
|
|
|
|
Using the most basic table markup, here's how `.table`-based tables look in Bootstrap. **All table styles are inherited in Bootstrap 4**, meaning any nested tables will be styled in the same manner as the parent.
|
|
|
|
{% example html %}
|
|
<table class="table">
|
|
<thead>
|
|
<tr>
|
|
<th>#</th>
|
|
<th>First Name</th>
|
|
<th>Last Name</th>
|
|
<th>Username</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<th scope="row">1</th>
|
|
<td>Mark</td>
|
|
<td>Otto</td>
|
|
<td>@mdo</td>
|
|
</tr>
|
|
<tr>
|
|
<th scope="row">2</th>
|
|
<td>Jacob</td>
|
|
<td>Thornton</td>
|
|
<td>@fat</td>
|
|
</tr>
|
|
<tr>
|
|
<th scope="row">3</th>
|
|
<td>Larry</td>
|
|
<td>the Bird</td>
|
|
<td>@twitter</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
{% endexample %}
|
|
|
|
You can also invert the colors—with light text on dark backgrounds—with `.table-inverse`.
|
|
|
|
{% example html %}
|
|
<table class="table table-inverse">
|
|
<thead>
|
|
<tr>
|
|
<th>#</th>
|
|
<th>First Name</th>
|
|
<th>Last Name</th>
|
|
<th>Username</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<th scope="row">1</th>
|
|
<td>Mark</td>
|
|
<td>Otto</td>
|
|
<td>@mdo</td>
|
|
</tr>
|
|
<tr>
|
|
<th scope="row">2</th>
|
|
<td>Jacob</td>
|
|
<td>Thornton</td>
|
|
<td>@fat</td>
|
|
</tr>
|
|
<tr>
|
|
<th scope="row">3</th>
|
|
<td>Larry</td>
|
|
<td>the Bird</td>
|
|
<td>@twitter</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
{% endexample %}
|
|
|
|
## Table head options
|
|
|
|
Similar to default and inverse tables, use one of two modifier classes to make `<thead>`s appear light or dark gray.
|
|
|
|
{% example html %}
|
|
<table class="table">
|
|
<thead class="thead-inverse">
|
|
<tr>
|
|
<th>#</th>
|
|
<th>First Name</th>
|
|
<th>Last Name</th>
|
|
<th>Username</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<th scope="row">1</th>
|
|
<td>Mark</td>
|
|
<td>Otto</td>
|
|
<td>@mdo</td>
|
|
</tr>
|
|
<tr>
|
|
<th scope="row">2</th>
|
|
<td>Jacob</td>
|
|
<td>Thornton</td>
|
|
<td>@fat</td>
|
|
</tr>
|
|
<tr>
|
|
<th scope="row">3</th>
|
|
<td>Larry</td>
|
|
<td>the Bird</td>
|
|
<td>@twitter</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
|
|
<table class="table">
|
|
<thead class="thead-default">
|
|
<tr>
|
|
<th>#</th>
|
|
<th>First Name</th>
|
|
<th>Last Name</th>
|
|
<th>Username</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<th scope="row">1</th>
|
|
<td>Mark</td>
|
|
<td>Otto</td>
|
|
<td>@mdo</td>
|
|
</tr>
|
|
<tr>
|
|
<th scope="row">2</th>
|
|
<td>Jacob</td>
|
|
<td>Thornton</td>
|
|
<td>@fat</td>
|
|
</tr>
|
|
<tr>
|
|
<th scope="row">3</th>
|
|
<td>Larry</td>
|
|
<td>the Bird</td>
|
|
<td>@twitter</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
{% endexample %}
|
|
|
|
## Striped rows
|
|
|
|
Use `.table-striped` to add zebra-striping to any table row within the `<tbody>`.
|
|
|
|
{% example html %}
|
|
<table class="table table-striped">
|
|
<thead>
|
|
<tr>
|
|
<th>#</th>
|
|
<th>First Name</th>
|
|
<th>Last Name</th>
|
|
<th>Username</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<th scope="row">1</th>
|
|
<td>Mark</td>
|
|
<td>Otto</td>
|
|
<td>@mdo</td>
|
|
</tr>
|
|
<tr>
|
|
<th scope="row">2</th>
|
|
<td>Jacob</td>
|
|
<td>Thornton</td>
|
|
<td>@fat</td>
|
|
</tr>
|
|
<tr>
|
|
<th scope="row">3</th>
|
|
<td>Larry</td>
|
|
<td>the Bird</td>
|
|
<td>@twitter</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
{% endexample %}
|
|
|
|
{% example html %}
|
|
<table class="table table-striped table-inverse">
|
|
<thead>
|
|
<tr>
|
|
<th>#</th>
|
|
<th>First Name</th>
|
|
<th>Last Name</th>
|
|
<th>Username</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<th scope="row">1</th>
|
|
<td>Mark</td>
|
|
<td>Otto</td>
|
|
<td>@mdo</td>
|
|
</tr>
|
|
<tr>
|
|
<th scope="row">2</th>
|
|
<td>Jacob</td>
|
|
<td>Thornton</td>
|
|
<td>@fat</td>
|
|
</tr>
|
|
<tr>
|
|
<th scope="row">3</th>
|
|
<td>Larry</td>
|
|
<td>the Bird</td>
|
|
<td>@twitter</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
{% endexample %}
|
|
|
|
## Bordered table
|
|
|
|
Add `.table-bordered` for borders on all sides of the table and cells.
|
|
|
|
{% example html %}
|
|
<table class="table table-bordered">
|
|
<thead>
|
|
<tr>
|
|
<th>#</th>
|
|
<th>First Name</th>
|
|
<th>Last Name</th>
|
|
<th>Username</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<th scope="row">1</th>
|
|
<td>Mark</td>
|
|
<td>Otto</td>
|
|
<td>@mdo</td>
|
|
</tr>
|
|
<tr>
|
|
<th scope="row">2</th>
|
|
<td>Mark</td>
|
|
<td>Otto</td>
|
|
<td>@TwBootstrap</td>
|
|
</tr>
|
|
<tr>
|
|
<th scope="row">3</th>
|
|
<td>Jacob</td>
|
|
<td>Thornton</td>
|
|
<td>@fat</td>
|
|
</tr>
|
|
<tr>
|
|
<th scope="row">4</th>
|
|
<td colspan="2">Larry the Bird</td>
|
|
<td>@twitter</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
{% endexample %}
|
|
|
|
{% example html %}
|
|
<table class="table table-bordered table-inverse">
|
|
<thead>
|
|
<tr>
|
|
<th>#</th>
|
|
<th>First Name</th>
|
|
<th>Last Name</th>
|
|
<th>Username</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<th scope="row">1</th>
|
|
<td>Mark</td>
|
|
<td>Otto</td>
|
|
<td>@mdo</td>
|
|
</tr>
|
|
<tr>
|
|
<th scope="row">2</th>
|
|
<td>Mark</td>
|
|
<td>Otto</td>
|
|
<td>@TwBootstrap</td>
|
|
</tr>
|
|
<tr>
|
|
<th scope="row">3</th>
|
|
<td>Jacob</td>
|
|
<td>Thornton</td>
|
|
<td>@fat</td>
|
|
</tr>
|
|
<tr>
|
|
<th scope="row">4</th>
|
|
<td colspan="2">Larry the Bird</td>
|
|
<td>@twitter</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
{% endexample %}
|
|
|
|
## Hoverable rows
|
|
|
|
Add `.table-hover` to enable a hover state on table rows within a `<tbody>`.
|
|
|
|
{% example html %}
|
|
<table class="table table-hover">
|
|
<thead>
|
|
<tr>
|
|
<th>#</th>
|
|
<th>First Name</th>
|
|
<th>Last Name</th>
|
|
<th>Username</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<th scope="row">1</th>
|
|
<td>Mark</td>
|
|
<td>Otto</td>
|
|
<td>@mdo</td>
|
|
</tr>
|
|
<tr>
|
|
<th scope="row">2</th>
|
|
<td>Jacob</td>
|
|
<td>Thornton</td>
|
|
<td>@fat</td>
|
|
</tr>
|
|
<tr>
|
|
<th scope="row">3</th>
|
|
<td colspan="2">Larry the Bird</td>
|
|
<td>@twitter</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
{% endexample %}
|
|
|
|
{% example html %}
|
|
<table class="table table-hover table-inverse">
|
|
<thead>
|
|
<tr>
|
|
<th>#</th>
|
|
<th>First Name</th>
|
|
<th>Last Name</th>
|
|
<th>Username</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<th scope="row">1</th>
|
|
<td>Mark</td>
|
|
<td>Otto</td>
|
|
<td>@mdo</td>
|
|
</tr>
|
|
<tr>
|
|
<th scope="row">2</th>
|
|
<td>Jacob</td>
|
|
<td>Thornton</td>
|
|
<td>@fat</td>
|
|
</tr>
|
|
<tr>
|
|
<th scope="row">3</th>
|
|
<td colspan="2">Larry the Bird</td>
|
|
<td>@twitter</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
{% endexample %}
|
|
|
|
## Small table
|
|
|
|
Add `.table-sm` to make tables more compact by cutting cell padding in half.
|
|
|
|
{% example html %}
|
|
<table class="table table-sm">
|
|
<thead>
|
|
<tr>
|
|
<th>#</th>
|
|
<th>First Name</th>
|
|
<th>Last Name</th>
|
|
<th>Username</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<th scope="row">1</th>
|
|
<td>Mark</td>
|
|
<td>Otto</td>
|
|
<td>@mdo</td>
|
|
</tr>
|
|
<tr>
|
|
<th scope="row">2</th>
|
|
<td>Jacob</td>
|
|
<td>Thornton</td>
|
|
<td>@fat</td>
|
|
</tr>
|
|
<tr>
|
|
<th scope="row">3</th>
|
|
<td colspan="2">Larry the Bird</td>
|
|
<td>@twitter</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
{% endexample %}
|
|
|
|
{% example html %}
|
|
<table class="table table-sm table-inverse">
|
|
<thead>
|
|
<tr>
|
|
<th>#</th>
|
|
<th>First Name</th>
|
|
<th>Last Name</th>
|
|
<th>Username</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<th scope="row">1</th>
|
|
<td>Mark</td>
|
|
<td>Otto</td>
|
|
<td>@mdo</td>
|
|
</tr>
|
|
<tr>
|
|
<th scope="row">2</th>
|
|
<td>Jacob</td>
|
|
<td>Thornton</td>
|
|
<td>@fat</td>
|
|
</tr>
|
|
<tr>
|
|
<th scope="row">3</th>
|
|
<td colspan="2">Larry the Bird</td>
|
|
<td>@twitter</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
{% endexample %}
|
|
|
|
## Contextual classes
|
|
|
|
Use contextual classes to color table rows or individual cells.
|
|
|
|
<div class="bd-example">
|
|
<table class="table">
|
|
<thead>
|
|
<tr>
|
|
<th>Type</th>
|
|
<th>Column heading</th>
|
|
<th>Column heading</th>
|
|
<th>Column heading</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr class="table-active">
|
|
<th scope="row">Active</th>
|
|
<td>Column content</td>
|
|
<td>Column content</td>
|
|
<td>Column content</td>
|
|
</tr>
|
|
<tr>
|
|
<th scope="row">Default</th>
|
|
<td>Column content</td>
|
|
<td>Column content</td>
|
|
<td>Column content</td>
|
|
</tr>
|
|
|
|
{% for color in site.data.theme-colors %}
|
|
<tr class="table-{{ color.name }}">
|
|
<th scope="row">{{ color.name | capitalize }}</th>
|
|
<td>Column content</td>
|
|
<td>Column content</td>
|
|
<td>Column content</td>
|
|
</tr>{% endfor %}
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
|
|
{% highlight html %}
|
|
<!-- On rows -->
|
|
<tr class="table-active">...</tr>
|
|
{% for color in site.data.theme-colors %}
|
|
<tr class="table-{{ color.name }}">...</tr>{% endfor %}
|
|
|
|
<!-- On cells (`td` or `th`) -->
|
|
<tr>
|
|
<td class="table-active">...</td>
|
|
{% for color in site.data.theme-colors %}
|
|
<td class="table-{{ color.name }}">...</td>{% endfor %}
|
|
</tr>
|
|
{% endhighlight %}
|
|
|
|
Regular table background variants are not available with the inverse table, however, you may use [text or background utilities]({{ site.baseurl }}/docs/{{ site.docs_version }}/utilities/colors/) to achieve similar styles.
|
|
|
|
<div class="bd-example">
|
|
<table class="table table-inverse">
|
|
<thead>
|
|
<tr>
|
|
<th>#</th>
|
|
<th>Column heading</th>
|
|
<th>Column heading</th>
|
|
<th>Column heading</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr class="bg-primary">
|
|
<th scope="row">1</th>
|
|
<td>Column content</td>
|
|
<td>Column content</td>
|
|
<td>Column content</td>
|
|
</tr>
|
|
<tr>
|
|
<th scope="row">2</th>
|
|
<td>Column content</td>
|
|
<td>Column content</td>
|
|
<td>Column content</td>
|
|
</tr>
|
|
<tr class="bg-success">
|
|
<th scope="row">3</th>
|
|
<td>Column content</td>
|
|
<td>Column content</td>
|
|
<td>Column content</td>
|
|
</tr>
|
|
<tr>
|
|
<th scope="row">4</th>
|
|
<td>Column content</td>
|
|
<td>Column content</td>
|
|
<td>Column content</td>
|
|
</tr>
|
|
<tr class="bg-info">
|
|
<th scope="row">5</th>
|
|
<td>Column content</td>
|
|
<td>Column content</td>
|
|
<td>Column content</td>
|
|
</tr>
|
|
<tr>
|
|
<th scope="row">6</th>
|
|
<td>Column content</td>
|
|
<td>Column content</td>
|
|
<td>Column content</td>
|
|
</tr>
|
|
<tr class="bg-warning">
|
|
<th scope="row">7</th>
|
|
<td>Column content</td>
|
|
<td>Column content</td>
|
|
<td>Column content</td>
|
|
</tr>
|
|
<tr>
|
|
<th scope="row">8</th>
|
|
<td>Column content</td>
|
|
<td>Column content</td>
|
|
<td>Column content</td>
|
|
</tr>
|
|
<tr class="bg-danger">
|
|
<th scope="row">9</th>
|
|
<td>Column content</td>
|
|
<td>Column content</td>
|
|
<td>Column content</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
|
|
{% highlight html %}
|
|
<!-- On rows -->
|
|
<tr class="bg-primary">...</tr>
|
|
<tr class="bg-success">...</tr>
|
|
<tr class="bg-warning">...</tr>
|
|
<tr class="bg-danger">...</tr>
|
|
<tr class="bg-info">...</tr>
|
|
|
|
<!-- On cells (`td` or `th`) -->
|
|
<tr>
|
|
<td class="bg-primary">...</td>
|
|
<td class="bg-success">...</td>
|
|
<td class="bg-warning">...</td>
|
|
<td class="bg-danger">...</td>
|
|
<td class="bg-info">...</td>
|
|
</tr>
|
|
{% endhighlight %}
|
|
|
|
{% capture callout-include %}{% include callout-warning-color-assistive-technologies.md %}{% endcapture %}
|
|
{{ callout-include | markdownify }}
|
|
|
|
## Responsive tables
|
|
|
|
Create responsive tables by adding `.table-responsive` to any `.table` 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.
|
|
|
|
{% callout warning %}
|
|
#### Vertical clipping/truncation
|
|
|
|
Responsive tables make use of `overflow-y: hidden`, which clips off any content that goes beyond the bottom or top edges of the table. In particular, this can clip off dropdown menus and other third-party widgets.
|
|
{% endcallout %}
|
|
|
|
<div class="bd-example">
|
|
<table class="table table-responsive">
|
|
<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>
|
|
<th scope="row">1</th>
|
|
<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>
|
|
<th scope="row">2</th>
|
|
<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>
|
|
<th scope="row">3</th>
|
|
<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>
|
|
|
|
<table class="table table-bordered table-responsive">
|
|
<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>
|
|
<th scope="row">1</th>
|
|
<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>
|
|
<th scope="row">2</th>
|
|
<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>
|
|
<th scope="row">3</th>
|
|
<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>
|
|
|
|
{% highlight html %}
|
|
<table class="table table-responsive">
|
|
...
|
|
</table>
|
|
{% endhighlight %}
|