tables.less 5.37 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
12
  border-collapse: collapse;
  border-spacing: 0;
}

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-base;
21
22
23
24
  // Cells
  th,
  td {
    padding: 8px;
25
    line-height: @line-height-base;
26
    text-align: left;
27
    vertical-align: top;
28
    border-top: 1px solid @table-border;
29
30
31
32
  }
  th {
    font-weight: bold;
  }
33
34
35
  // Bottom align for column headings
  thead th {
    vertical-align: bottom;
36
37
  }
  // Remove top border from thead by default
38
39
  caption + thead tr:first-child th,
  caption + thead tr:first-child td,
40
41
42
43
  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 {
44
45
46
47
    border-top: 0;
  }
  // Account for multiple tbody instances
  tbody + tbody {
48
    border-top: 2px solid @table-border;
49
  }
Mark Otto's avatar
Mark Otto committed
50
51
52

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

57
58


59
60
// CONDENSED TABLE W/ HALF PADDING
// -------------------------------
61

62
.table-condensed {
63
64
  th,
  td {
65
    padding: 4px 5px;
66
  }
67
68
69
}


70

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

74
.table-bordered {
75
  border: 1px solid @table-border;
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
  th,
  td {
81
    border-left: 1px solid @table-border;
82
  }
83
  // Prevent a double border
84
85
86
87
88
89
  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,
90
  thead:first-child tr:first-child th,
91
  tbody:first-child tr:first-child th,
92
  tbody:first-child tr:first-child td {
Mark Otto's avatar
Mark Otto committed
93
    border-top: 0;
94
  }
95
  // For first th/td in the first row in the first thead or tbody
Mark Otto's avatar
Mark Otto committed
96
  thead:first-child tr:first-child > th:first-child,
97
98
  tbody:first-child tr:first-child > td:first-child,
  tbody:first-child tr:first-child > th:first-child {
99
    border-top-left-radius: @border-radius-base;
100
  }
101
  // For last th/td in the first row in the first thead or tbody
Mark Otto's avatar
Mark Otto committed
102
  thead:first-child tr:first-child > th:last-child,
103
104
  tbody:first-child tr:first-child > td:last-child,
  tbody:first-child tr:first-child > th:last-child {
105
    border-top-right-radius: @border-radius-base;
106
  }
107
  // 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
108
109
  thead:last-child tr:last-child > th:first-child,
  tbody:last-child tr:last-child > td:first-child,
110
111
112
  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 {
113
    border-bottom-left-radius: @border-radius-base;
114
  }
115
  // 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
116
117
  thead:last-child tr:last-child > th:last-child,
  tbody:last-child tr:last-child > td:last-child,
118
119
120
  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 {
121
    border-bottom-right-radius: @border-radius-base;
amid2887's avatar
amid2887 committed
122
123
124
  }

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

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

Jacob Thornton's avatar
Jacob Thornton committed
146
147
}

148

149

150
151
152
153
// ZEBRA-STRIPING
// --------------

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


164

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

177

178

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

182
// Reset default grid behavior
183
table td[class*="span"],
Mark Otto's avatar
Mark Otto committed
184
table th[class*="span"] {
185
186
187
188
189
  display: table-cell;
  float: none; // undo default grid column styles
  margin-left: 0; // undo default grid column styles
}

190
191
192
193
// TABLE BACKGROUNDS
// -----------------
// Exact selectors below required to override .table-striped

194
.table tbody tr {
195
  &.success > td {
Mark Otto's avatar
Mark Otto committed
196
    background-color: @state-success-background;
197
  }
198
  &.error > td {
Mark Otto's avatar
Mark Otto committed
199
    background-color: @state-error-background;
200
  }
201
  &.warning > td {
Mark Otto's avatar
Mark Otto committed
202
    background-color: @state-warning-background;
203
  }
204
}
205
206
207

// Hover states for .table-hover
.table-hover tbody tr {
208
  &.success:hover > td {
Mark Otto's avatar
Mark Otto committed
209
    background-color: darken(@state-success-background, 5%);
210
  }
211
  &.error:hover > td {
Mark Otto's avatar
Mark Otto committed
212
    background-color: darken(@state-error-background, 5%);
213
  }
214
  &.warning:hover > td {
Mark Otto's avatar
Mark Otto committed
215
    background-color: darken(@state-warning-background, 5%);
216
217
  }
}