tables.less 4.93 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
  }
50
51
}

52
53


54
55
// CONDENSED TABLE W/ HALF PADDING
// -------------------------------
56

57
.table-condensed {
58
59
  th,
  td {
60
    padding: 4px 5px;
61
  }
62
63
64
}


65

66
67
68
// BORDERED VERSION
// ----------------

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

  // Clear border-radius for first and last td in the last row in the last tbody for table with tfoot
  tfoot + tbody:last-child tr:last-child td:first-child {
113
    border-bottom-left-radius: 0;
114
  }
amid2887's avatar
amid2887 committed
115
  tfoot + tbody:last-child tr:last-child td:last-child {
116
    border-bottom-right-radius: 0;
amid2887's avatar
amid2887 committed
117
118
  }

119

120
  // Special fixes to round the left border on the first td/th
121
122
123
124
  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 {
125
    border-top-left-radius: @border-radius-base;
126
127
128
129
130
  }
  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 {
131
    border-top-right-radius: @border-radius-base;
132
  }
133

Jacob Thornton's avatar
Jacob Thornton committed
134
135
}

136

137

138
139
140
141
// ZEBRA-STRIPING
// --------------

// Default zebra-stripe styles (alternating gray and transparent backgrounds)
142
.table-striped {
143
144
145
  tbody {
    tr:nth-child(odd) td,
    tr:nth-child(odd) th {
146
      background-color: @table-background-accent;
147
148
149
150
151
    }
  }
}


152

153
154
155
// HOVER EFFECT
// ------------
// Placed here since it has to come after the potential zebra striping
156
.table-hover {
157
158
159
  tbody {
    tr:hover td,
    tr:hover th {
160
      background-color: @table-background-hover;
161
    }
162
163
164
  }
}

165

166

167
168
// TABLE CELL SIZING
// -----------------
169

170
// Reset default grid behavior
171
table td[class*="span"],
Mark Otto's avatar
Mark Otto committed
172
table th[class*="span"] {
173
174
175
176
177
  display: table-cell;
  float: none; // undo default grid column styles
  margin-left: 0; // undo default grid column styles
}

178
179
180
181
// TABLE BACKGROUNDS
// -----------------
// Exact selectors below required to override .table-striped

182
183
.table tbody tr {
  &.success td {
Mark Otto's avatar
Mark Otto committed
184
    background-color: @state-success-background;
185
  }
186
  &.error td {
Mark Otto's avatar
Mark Otto committed
187
    background-color: @state-error-background;
188
  }
189
  &.warning td {
Mark Otto's avatar
Mark Otto committed
190
    background-color: @state-warning-background;
191
  }
192
  &.info td {
Mark Otto's avatar
Mark Otto committed
193
    background-color: @state-info-background;
194
195
  }
}
196
197
198
199

// Hover states for .table-hover
.table-hover tbody tr {
  &.success:hover td {
Mark Otto's avatar
Mark Otto committed
200
    background-color: darken(@state-success-background, 5%);
201
202
  }
  &.error:hover td {
Mark Otto's avatar
Mark Otto committed
203
    background-color: darken(@state-error-background, 5%);
204
205
  }
  &.warning:hover td {
Mark Otto's avatar
Mark Otto committed
206
    background-color: darken(@state-warning-background, 5%);
207
208
  }
  &.info:hover td {
Mark Otto's avatar
Mark Otto committed
209
    background-color: darken(@state-info-background, 5%);
210
211
  }
}