tables.less 5.33 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
  thead,
23
24
  tbody,
  tfoot {
25
26
27
28
29
30
31
32
33
    > tr {
      > th,
      > td {
        padding: 8px;
        line-height: @line-height-base;
        vertical-align: top;
        border-top: 1px solid @table-border-color;
      }
    }
34
  }
35
  // Bottom align for column headings
36
  thead > tr > th {
37
    vertical-align: bottom;
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


62
63
// CONDENSED TABLE W/ HALF PADDING
// -------------------------------
64

65
.table-condensed {
66
  thead,
67
68
  tbody,
  tfoot {
69
70
71
72
73
74
    > tr {
      > th,
      > td {
        padding: 4px 5px;
      }
    }
75
  }
76
77
78
}


79

80
81
82
// BORDERED VERSION
// ----------------

83
.table-bordered {
84
  border: 1px solid @table-border-color;
85
  border-collapse: separate; // Done so we can round those corners!
Jacob Thornton's avatar
Jacob Thornton committed
86
  border-left: 0;
87
  border-radius: @border-radius-base;
88

89
  > thead,
90
91
  > tbody,
  > tfoot {
92
93
94
95
96
97
    > tr {
      > th,
      > td {
        border-left: 1px solid @table-border-color;
      }
    }
98
  }
99
  // Prevent a double border
100
101
102
103
104
105
106
107
108
  > 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
109
    border-top: 0;
110
  }
liuyl's avatar
liuyl committed
111
112
113
114
115
116
117
118
119
120
121
  > thead:first-child > tr:first-child > th,
  > tbody:first-child > tr:first-child > td,
  > tbody:first-child > tr:first-child > th {
    // For first th/td in the first row in the first thead or tbody
    &:first-child{
      border-top-left-radius: @border-radius-base;
    }
    // For last th/td in the first row in the first thead or tbody
    &:last-child{
      border-top-right-radius: @border-radius-base;
    }
122
  }
liuyl's avatar
liuyl committed
123
124
125
126
127
128
129
130
131
132
133
134
135
  > thead:last-child > tr:last-child > th,
  > tbody:last-child > tr:last-child > td,
  > tbody:last-child > tr:last-child > th,
  > tfoot:last-child > tr:last-child > td,
  > tfoot:last-child > tr:last-child > th {
    // For first th/td (can be either) in the last row in the last thead, tbody, and tfoot
    &:first-child{
      border-bottom-left-radius: @border-radius-base;
    }
    // For last th/td (can be either) in the last row in the last thead, tbody, and tfoot
    &:last-child{
      border-bottom-right-radius: @border-radius-base;
    }
amid2887's avatar
amid2887 committed
136
137
138
  }

  // Clear border-radius for first and last td in the last row in the last tbody for table with tfoot
139
  > tfoot + tbody:last-child > tr:last-child > td:first-child {
140
    border-bottom-left-radius: 0;
141
  }
142
  > tfoot + tbody:last-child > tr:last-child > td:last-child {
143
    border-bottom-right-radius: 0;
amid2887's avatar
amid2887 committed
144
145
  }

146
  // Special fixes to round the left border on the first td/th
147
148
149
150
151
152
153
154
155
156
  > caption,
  > colgroup {
    + thead > tr:first-child > th,
    + tbody > tr:first-child > td {
      &:first-child {
        border-top-left-radius: @border-radius-base;
      }
      &:last-child {
        border-top-right-radius: @border-radius-base;
      }
liuyl's avatar
liuyl committed
157
    }
158
  }
Jacob Thornton's avatar
Jacob Thornton committed
159
160
}

161

162

163
164
165
166
// ZEBRA-STRIPING
// --------------

// Default zebra-stripe styles (alternating gray and transparent backgrounds)
167
.table-striped {
168
  > tbody {
169
170
171
172
173
    > tr:nth-child(odd) {
      > td,
      > th {
        background-color: @table-bg-accent;
      }
174
175
176
177
178
    }
  }
}


179

180
181
// HOVER EFFECT
// ------------
182

183
// Placed here since it has to come after the potential zebra striping
184
.table-hover {
185
  > tbody {
186
187
188
189
190
    > tr:hover {
      > td,
      > th {
        background-color: @table-bg-hover;
      }
191
    }
192
193
194
  }
}

195

196

197
198
// TABLE CELL SIZING
// -----------------
199

200
// Reset default table behavior
201
table col[class^="col-"] {
202
203
204
  float: none;
  display: table-column;
}
205
table {
206
207
  td,
  th {
208
209
210
211
212
    &[class^="col-"] {
      float: none;
      display: table-cell;
    }
  }
213
214
}

215
216


217
218
219
220
// TABLE BACKGROUNDS
// -----------------
// Exact selectors below required to override .table-striped

221
.table > tbody > tr {
222
223
  > td.success,
  > th.success,
224
  &.success > td {
225
    background-color: @state-success-bg;
226
    border-color: @state-success-border;
227
  }
228
229
230
  > td.danger,
  > th.danger,
  &.danger > td {
231
    background-color: @state-danger-bg;
232
    border-color: @state-danger-border;
233
  }
234
235
  > td.warning,
  > th.warning,
236
  &.warning > td {
237
    background-color: @state-warning-bg;
238
    border-color: @state-warning-border;
239
  }
240
}
241
242

// Hover states for .table-hover
243
.table-hover > tbody > tr {
244
245
  > td.success:hover,
  > th.success:hover,
246
  &.success:hover > td {
247
    background-color: darken(@state-success-bg, 5%);
248
    border-color: darken(@state-success-border, 5%);
249
  }
250
251
252
  > td.danger:hover,
  > th.danger:hover,
  &.danger:hover > td {
253
    background-color: darken(@state-danger-bg, 5%);
254
    border-color: darken(@state-danger-border, 5%);
255
  }
256
257
  > td.warning:hover,
  > th.warning:hover,
258
  &.warning:hover > td {
259
    background-color: darken(@state-warning-bg, 5%);
260
    border-color: darken(@state-warning-border, 5%);
261
262
  }
}