tables.less 6.09 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
16
// BASELINE STYLES
// ---------------
Jacob Thornton's avatar
Jacob Thornton committed
17

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

  // Nesting
  .table {
51
    background-color: @body-bg;
Mark Otto's avatar
Mark Otto committed
52
  }
53
54
}

55
56


57
58
// CONDENSED TABLE W/ HALF PADDING
// -------------------------------
59

60
.table-condensed {
61
62
63
64
  thead > tr > th,
  tbody > tr > th,
  thead > tr > td,
  tbody > tr > td {
65
    padding: 4px 5px;
66
  }
67
68
69
}


70

71
72
73
// BORDERED VERSION
// ----------------

74
.table-bordered {
75
  border: 1px solid @table-border-color;
76
  border-collapse: separate; // Done so we can round those corners!
Jacob Thornton's avatar
Jacob Thornton committed
77
  border-left: 0;
78
  border-radius: @border-radius-base;
79
80
81
82
83

  > thead > tr > th,
  > tbody > tr > th,
  > thead > tr > td,
  > tbody > tr > td {
84
    border-left: 1px solid @table-border-color;
85
  }
86
  // Prevent a double border
87
88
89
90
91
92
93
94
95
  > caption + thead > tr:first-child th,
  > caption + tbody > tr:first-child th,
  > caption + tbody > tr:first-child td,
  > colgroup + thead > tr:first-child th,
  > colgroup + tbody > tr:first-child th,
  > colgroup + tbody > tr:first-child td,
  > thead:first-child > tr:first-child th,
  > tbody:first-child > tr:first-child th,
  > tbody:first-child > tr:first-child td {
Mark Otto's avatar
Mark Otto committed
96
    border-top: 0;
97
  }
98
  // For first th/td in the first row in the first thead or tbody
99
100
101
  > thead:first-child > tr:first-child > th:first-child,
  > tbody:first-child > tr:first-child > td:first-child,
  > tbody:first-child > tr:first-child > th:first-child {
102
    border-top-left-radius: @border-radius-base;
103
  }
104
  // For last th/td in the first row in the first thead or tbody
105
106
107
  > thead:first-child > tr:first-child > th:last-child,
  > tbody:first-child > tr:first-child > td:last-child,
  > tbody:first-child > tr:first-child > th:last-child {
108
    border-top-right-radius: @border-radius-base;
109
  }
110
  // For first th/td (can be either) in the last row in the last thead, tbody, and tfoot
111
112
113
114
115
  > thead:last-child > tr:last-child > th:first-child,
  > tbody:last-child > tr:last-child > td:first-child,
  > tbody:last-child > tr:last-child > th:first-child,
  > tfoot:last-child > tr:last-child > td:first-child,
  > tfoot:last-child > tr:last-child > th:first-child {
116
    border-bottom-left-radius: @border-radius-base;
117
  }
118
  // For last th/td (can be either) in the last row in the last thead, tbody, and tfoot
119
120
121
122
123
  > thead:last-child > tr:last-child > th:last-child,
  > tbody:last-child > tr:last-child > td:last-child,
  > tbody:last-child > tr:last-child > th:last-child,
  > tfoot:last-child > tr:last-child > td:last-child,
  > tfoot:last-child > tr:last-child > th:last-child {
124
    border-bottom-right-radius: @border-radius-base;
amid2887's avatar
amid2887 committed
125
126
127
  }

  // Clear border-radius for first and last td in the last row in the last tbody for table with tfoot
128
  > tfoot + tbody:last-child > tr:last-child > td:first-child {
129
    border-bottom-left-radius: 0;
130
  }
131
  > tfoot + tbody:last-child > tr:last-child > td:last-child {
132
    border-bottom-right-radius: 0;
amid2887's avatar
amid2887 committed
133
134
  }

135
  // Special fixes to round the left border on the first td/th
136
137
138
139
  > caption + thead > tr:first-child > th:first-child,
  > caption + tbody > tr:first-child > td:first-child,
  > colgroup + thead > tr:first-child > th:first-child,
  > colgroup + tbody > tr:first-child > td:first-child {
140
    border-top-left-radius: @border-radius-base;
141
  }
142
143
144
145
  > caption + thead > tr:first-child > th:last-child,
  > caption + tbody > tr:first-child > td:last-child,
  > colgroup + thead > tr:first-child > th:last-child,
  > colgroup + tbody > tr:first-child > td:last-child {
146
    border-top-right-radius: @border-radius-base;
147
  }
148

Jacob Thornton's avatar
Jacob Thornton committed
149
150
}

151

152

153
154
155
156
// ZEBRA-STRIPING
// --------------

// Default zebra-stripe styles (alternating gray and transparent backgrounds)
157
.table-striped {
158
  > tbody {
Mark Otto's avatar
Mark Otto committed
159
160
    > tr:nth-child(odd) > td,
    > tr:nth-child(odd) > th {
161
      background-color: @table-bg-accent;
162
163
164
165
166
    }
  }
}


167

168
169
// HOVER EFFECT
// ------------
170

171
// Placed here since it has to come after the potential zebra striping
172
.table-hover {
173
174
175
  > tbody {
    > tr:hover > td,
    > tr:hover > th {
176
      background-color: @table-bg-hover;
177
    }
178
179
180
  }
}

181

182

183
184
// TABLE CELL SIZING
// -----------------
185

186
// Reset default table behavior
187
table col[class^="col-"] {
188
189
190
  float: none;
  display: table-column;
}
191
192
table td[class^="col-"],
table th[class^="col-"] {
193
  float: none;
194
195
196
  display: table-cell;
}

197
198


199
200
201
202
// TABLE BACKGROUNDS
// -----------------
// Exact selectors below required to override .table-striped

203
.table > tbody > tr {
204
205
  > td.success,
  > th.success,
206
  &.success > td {
207
    background-color: @state-success-bg;
208
    border-color: @state-success-border;
209
  }
210
211
212
  > td.danger,
  > th.danger,
  &.danger > td {
213
    background-color: @state-danger-bg;
214
    border-color: @state-danger-border;
215
  }
216
217
  > td.warning,
  > th.warning,
218
  &.warning > td {
219
    background-color: @state-warning-bg;
220
    border-color: @state-warning-border;
221
  }
222
}
223
224

// Hover states for .table-hover
225
.table-hover > tbody > tr {
226
227
  > td.success:hover,
  > th.success:hover,
228
  &.success:hover > td {
229
    background-color: darken(@state-success-bg, 5%);
230
    border-color: darken(@state-success-border, 5%);
231
  }
232
233
234
  > td.danger:hover,
  > th.danger:hover,
  &.danger:hover > td {
235
    background-color: darken(@state-danger-bg, 5%);
236
    border-color: darken(@state-danger-border, 5%);
237
  }
238
239
  > td.warning:hover,
  > th.warning:hover,
240
  &.warning:hover > td {
241
    background-color: darken(@state-warning-bg, 5%);
242
    border-color: darken(@state-warning-border, 5%);
243
244
  }
}