tables.less 5.46 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
  }
liuyl's avatar
liuyl committed
98
99
100
101
102
103
104
105
106
107
108
  > 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;
    }
109
  }
liuyl's avatar
liuyl committed
110
111
112
113
114
115
116
117
118
119
120
121
122
  > 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
123
124
125
  }

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

133
  // Special fixes to round the left border on the first td/th
liuyl's avatar
liuyl committed
134
135
136
137
138
139
140
141
142
143
  > caption + thead > tr:first-child > th,
  > caption + tbody > tr:first-child > td,
  > colgroup + thead > tr:first-child > th,
  > colgroup + tbody > tr:first-child > td {
    &:first-child{
      border-top-left-radius: @border-radius-base;
    }
    &:last-child{
      border-top-right-radius: @border-radius-base;
    }
144
  }
Jacob Thornton's avatar
Jacob Thornton committed
145
146
}

147

148

149
150
151
152
// ZEBRA-STRIPING
// --------------

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


163

164
165
// HOVER EFFECT
// ------------
166

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

177

178

179
180
// TABLE CELL SIZING
// -----------------
181

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

193
194


195
196
197
198
// TABLE BACKGROUNDS
// -----------------
// Exact selectors below required to override .table-striped

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

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