tables.less 5.8 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-background;
9
10
11
  border-collapse: collapse;
  border-spacing: 0;
}
12
13
14
th {
  text-align: left;
}
15
16


17
18
// BASELINE STYLES
// ---------------
Jacob Thornton's avatar
Jacob Thornton committed
19

20
.table {
Jacob Thornton's avatar
Jacob Thornton committed
21
  width: 100%;
22
  margin-bottom: @line-height-base;
23
24
25
26
  // Cells
  th,
  td {
    padding: 8px;
27
    line-height: @line-height-base;
28
    vertical-align: top;
29
    border-top: 1px solid @table-border;
30
  }
31
32
33
  // Bottom align for column headings
  thead th {
    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;
47
  }
Mark Otto's avatar
Mark Otto committed
48
49
50

  // Nesting
  .table {
51
    background-color: @body-background;
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
  th,
  td {
63
    padding: 4px 5px;
64
  }
65
66
67
}


68

69
70
71
// BORDERED VERSION
// ----------------

72
.table-bordered {
73
  border: 1px solid @table-border;
74
  border-collapse: separate; // Done so we can round those corners!
Jacob Thornton's avatar
Jacob Thornton committed
75
  border-left: 0;
76
  border-radius: @border-radius-base;
77
78
  th,
  td {
79
    border-left: 1px solid @table-border;
80
  }
81
  // Prevent a double border
82
83
84
85
86
87
  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,
88
  thead:first-child tr:first-child th,
89
  tbody:first-child tr:first-child th,
90
  tbody:first-child tr:first-child td {
Mark Otto's avatar
Mark Otto committed
91
    border-top: 0;
92
  }
93
  // For first th/td in the first row in the first thead or tbody
Mark Otto's avatar
Mark Otto committed
94
  thead:first-child tr:first-child > th:first-child,
95
96
  tbody:first-child tr:first-child > td:first-child,
  tbody:first-child tr:first-child > th:first-child {
97
    border-top-left-radius: @border-radius-base;
98
  }
99
  // For last th/td in the first row in the first thead or tbody
Mark Otto's avatar
Mark Otto committed
100
  thead:first-child tr:first-child > th:last-child,
101
102
  tbody:first-child tr:first-child > td:last-child,
  tbody:first-child tr:first-child > th:last-child {
103
    border-top-right-radius: @border-radius-base;
104
  }
105
  // For first th/td (can be either) in the last row in the last thead, tbody, and tfoot
Mark Otto's avatar
Mark Otto committed
106
107
  thead:last-child tr:last-child > th:first-child,
  tbody:last-child tr:last-child > td:first-child,
108
109
110
  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 {
111
    border-bottom-left-radius: @border-radius-base;
112
  }
113
  // For last th/td (can be either) in the last row in the last thead, tbody, and tfoot
Mark Otto's avatar
Mark Otto committed
114
115
  thead:last-child tr:last-child > th:last-child,
  tbody:last-child tr:last-child > td:last-child,
116
117
118
  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 {
119
    border-bottom-right-radius: @border-radius-base;
amid2887's avatar
amid2887 committed
120
121
122
  }

  // Clear border-radius for first and last td in the last row in the last tbody for table with tfoot
123
  tfoot + tbody:last-child tr:last-child > td:first-child {
124
    border-bottom-left-radius: 0;
125
  }
126
  tfoot + tbody:last-child tr:last-child > td:last-child {
127
    border-bottom-right-radius: 0;
amid2887's avatar
amid2887 committed
128
129
  }

130
  // Special fixes to round the left border on the first td/th
131
132
133
134
  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 {
135
    border-top-left-radius: @border-radius-base;
136
137
138
139
140
  }
  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 {
141
    border-top-right-radius: @border-radius-base;
142
  }
143

Jacob Thornton's avatar
Jacob Thornton committed
144
145
}

146

147

148
149
150
151
// ZEBRA-STRIPING
// --------------

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


162

163
164
// HOVER EFFECT
// ------------
165

166
// Placed here since it has to come after the potential zebra striping
167
.table-hover {
168
169
170
  > tbody {
    > tr:hover > td,
    > tr:hover > th {
171
      background-color: @table-background-hover;
172
    }
173
174
175
  }
}

176

177

178
179
// TABLE CELL SIZING
// -----------------
180

181
// Reset default table behavior
Mark Otto's avatar
Mark Otto committed
182
table col[class*="col-span-"] {
183
184
185
  float: none;
  display: table-column;
}
Mark Otto's avatar
Mark Otto committed
186
187
table td[class*="col-span-"],
table th[class*="col-span-"] {
188
  float: none;
189
190
191
  display: table-cell;
}

192
193
194
195
// TABLE BACKGROUNDS
// -----------------
// Exact selectors below required to override .table-striped

196
.table > tbody > tr {
197
198
  > td.success,
  > th.success,
199
  &.success > td {
200
    background-color: @state-success-bg;
201
    border-color: @state-success-border;
202
  }
203
204
205
  > td.danger,
  > th.danger,
  &.danger > td {
206
    background-color: @state-danger-bg;
207
    border-color: @state-danger-border;
208
  }
209
210
  > td.warning,
  > th.warning,
211
  &.warning > td {
212
    background-color: @state-warning-bg;
213
    border-color: @state-warning-border;
214
  }
215
}
216
217

// Hover states for .table-hover
218
.table-hover > tbody > tr {
219
220
  > td.success:hover,
  > th.success:hover,
221
  &.success:hover > td {
222
    background-color: darken(@state-success-bg, 5%);
223
    border-color: darken(@state-success-border, 5%);
224
  }
225
226
227
  > td.danger:hover,
  > th.danger:hover,
  &.danger:hover > td {
228
    background-color: darken(@state-danger-bg, 5%);
229
    border-color: darken(@state-danger-border, 5%);
230
  }
231
232
  > td.warning:hover,
  > th.warning:hover,
233
  &.warning:hover > td {
234
    background-color: darken(@state-warning-bg, 5%);
235
    border-color: darken(@state-warning-border, 5%);
236
237
  }
}