tables.less 5.3 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
26
27
28
29
30
31
32
  thead,
  tbody {
    > tr {
      > th,
      > td {
        padding: 8px;
        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
38
  }
  // Remove top border from thead by default
39
40
41
42
43
44
45
46
  caption + thead,
  colgroup + thead,
  thead:first-child {
    tr:first-child {
      th, td {
        border-top: 0;
      }
    }
47
48
49
  }
  // Account for multiple tbody instances
  tbody + tbody {
50
    border-top: 2px solid @table-border-color;
51
  }
Mark Otto's avatar
Mark Otto committed
52
53
54

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

59
60


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

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


77

78
79
80
// BORDERED VERSION
// ----------------

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

87
88
89
90
91
92
93
94
  > thead,
  > tbody {
    > tr {
      > th,
      > td {
        border-left: 1px solid @table-border-color;
      }
    }
95
  }
96
  // Prevent a double border
97
98
99
100
101
102
103
104
105
  > 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
106
    border-top: 0;
107
  }
liuyl's avatar
liuyl committed
108
109
110
111
112
113
114
115
116
117
118
  > 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;
    }
119
  }
liuyl's avatar
liuyl committed
120
121
122
123
124
125
126
127
128
129
130
131
132
  > 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
133
134
135
  }

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

143
  // Special fixes to round the left border on the first td/th
144
145
146
147
148
149
150
151
152
153
  > 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
154
    }
155
  }
Jacob Thornton's avatar
Jacob Thornton committed
156
157
}

158

159

160
161
162
163
// ZEBRA-STRIPING
// --------------

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


176

177
178
// HOVER EFFECT
// ------------
179

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

192

193

194
195
// TABLE CELL SIZING
// -----------------
196

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

211
212


213
214
215
216
// TABLE BACKGROUNDS
// -----------------
// Exact selectors below required to override .table-striped

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

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