tables.less 4.02 KB
Newer Older
1
//
2
3
// Tables
// --------------------------------------------------
Jacob Thornton's avatar
Jacob Thornton committed
4

5

6
7
table {
  max-width: 100%;
8
  background-color: @table-bg;
9
}
10
11
12
th {
  text-align: left;
}
13
14


15
// Baseline styles
Jacob Thornton's avatar
Jacob Thornton committed
16

17
.table {
Jacob Thornton's avatar
Jacob Thornton committed
18
  width: 100%;
19
  margin-bottom: @line-height-computed;
20
  // Cells
21
  thead,
22
23
  tbody,
  tfoot {
24
25
26
    > tr {
      > th,
      > td {
27
        padding: @table-cell-padding;
28
29
30
31
32
        line-height: @line-height-base;
        vertical-align: top;
        border-top: 1px solid @table-border-color;
      }
    }
33
  }
34
  // Bottom align for column headings
35
  thead > tr > th {
36
    vertical-align: bottom;
37
    border-bottom: 2px solid @table-border-color;
38
39
  }
  // Remove top border from thead by default
40
41
42
43
44
45
46
47
  caption + thead,
  colgroup + thead,
  thead:first-child {
    tr:first-child {
      th, td {
        border-top: 0;
      }
    }
48
49
50
  }
  // Account for multiple tbody instances
  tbody + tbody {
51
    border-top: 2px solid @table-border-color;
52
  }
Mark Otto's avatar
Mark Otto committed
53
54
55

  // Nesting
  .table {
56
    background-color: @body-bg;
Mark Otto's avatar
Mark Otto committed
57
  }
58
59
}

60

61
// Condensed table w/ half padding
62

63
.table-condensed {
64
  thead,
65
66
  tbody,
  tfoot {
67
68
69
    > tr {
      > th,
      > td {
70
        padding: @table-condensed-cell-padding;
71
72
      }
    }
73
  }
74
75
76
}


77
// Bordered version
78
79
//
// Add borders all around the table and between all the columns.
80

81
.table-bordered {
82
  border: 1px solid @table-border-color;
83
  > thead,
84
85
  > tbody,
  > tfoot {
86
87
88
    > tr {
      > th,
      > td {
89
        border: 1px solid @table-border-color;
90
      }
liuyl's avatar
liuyl committed
91
    }
92
  }
93
94
95
96
97
98
99
100
  > thead {
    > tr {
      > th,
      > td {
        border-bottom-width: 2px;
      }
    }
  }
Jacob Thornton's avatar
Jacob Thornton committed
101
102
}

103

104
// Zebra-striping
105
//
106
// Default zebra-stripe styles (alternating gray and transparent backgrounds)
107

108
.table-striped {
109
  > tbody {
110
111
112
113
114
    > tr:nth-child(odd) {
      > td,
      > th {
        background-color: @table-bg-accent;
      }
115
116
117
118
119
    }
  }
}


120
// Hover effect
121
//
122
// Placed here since it has to come after the potential zebra striping
123

124
.table-hover {
125
  > tbody {
126
127
128
129
130
    > tr:hover {
      > td,
      > th {
        background-color: @table-bg-hover;
      }
131
    }
132
133
134
  }
}

135

136
// Table cell sizing
137
//
138
// Reset default table behavior
139

140
table col[class^="col-"] {
141
142
143
  float: none;
  display: table-column;
}
144
table {
145
146
  td,
  th {
147
148
149
150
151
    &[class^="col-"] {
      float: none;
      display: table-cell;
    }
  }
152
153
}

154

155
// Table backgrounds
156
//
157
158
// Exact selectors below required to override `.table-striped` and prevent
// inheritance to nested tables.
159

160
161
162
.table > thead > tr,
.table > tbody > tr,
.table > tfoot > tr {
163
164
  > td.active,
  > th.active,
165
166
  &.active > td,
  &.active > th  {
167
    background-color: @table-bg-active;
168
  }
169
}
170

171
// Generate the contextual variants
ggam's avatar
ggam committed
172
173
174
.table-row-variant(success; @state-success-bg; @state-success-border);
.table-row-variant(danger; @state-danger-bg; @state-danger-border);
.table-row-variant(warning; @state-warning-bg; @state-warning-border);
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
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
229
230
231
232
233
234
235
236


// Responsive tables
//
// Wrap your tables in `.table-scrollable` and we'll make them mobile friendly
// by enabling horizontal scrolling. Only applies <768px. Everything above that
// will display normally.

@media (max-width: @screen-sm) {
  .table-responsive {
    width: 100%;
    margin-bottom: 15px;
    overflow-y: hidden;
    overflow-x: scroll;
    border: 1px solid @table-border-color;

    // Tighten up spacing and give a background color
    > .table {
      margin-bottom: 0;
      background-color: #fff;

      // Ensure the content doesn't wrap
      > thead,
      > tbody,
      > tfoot {
        > tr {
          > th,
          > td {
            white-space: nowrap;
          }
        }
      }
    }

    // Special overrides for the bordered tables
    > .table-bordered {
      border: 0;

      // Nuke the appropriate borders so that the parent can handle them
      > thead,
      > tbody,
      > tfoot {
        > tr {
          > th:first-child,
          > td:first-child {
            border-left: 0;
          }
          > th:last-child,
          > td:last-child {
            border-right: 0;
          }
        }
        > tr:last-child {
          > th,
          > td {
            border-bottom: 0;
          }
        }
      }
    }
  }
}