tables.less 3.15 KB
Newer Older
1
2
3
4
//
// Tables.less
// Tables for, you guessed it, tabular data
// ----------------------------------------
Jacob Thornton's avatar
Jacob Thornton committed
5

6

7
8
9
10
11
12
13
14
15
// BASE TABLES
// -----------------

table {
  max-width: 100%;
  border-collapse: collapse;
  border-spacing: 0;
}

16
17
// BASELINE STYLES
// ---------------
Jacob Thornton's avatar
Jacob Thornton committed
18

19
.table {
Jacob Thornton's avatar
Jacob Thornton committed
20
  width: 100%;
21
  margin-bottom: @baseLineHeight;
22
23
24
25
26
27
  // Cells
  th,
  td {
    padding: 8px;
    line-height: @baseLineHeight;
    text-align: left;
28
    vertical-align: top;
29
30
31
32
33
    border-top: 1px solid #ddd;
  }
  th {
    font-weight: bold;
  }
34
35
36
  // Bottom align for column headings
  thead th {
    vertical-align: bottom;
37
38
39
40
41
42
43
44
45
46
  }
  // Remove top border from thead by default
  thead:first-child tr th,
  thead:first-child tr td {
    border-top: 0;
  }
  // Account for multiple tbody instances
  tbody + tbody {
    border-top: 2px solid #ddd;
  }
47
48
}

49
50


51
52
// CONDENSED TABLE W/ HALF PADDING
// -------------------------------
53

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


// BORDERED VERSION
// ----------------

65
.table-bordered {
66
67
  border: 1px solid #ddd;
  border-collapse: separate; // Done so we can round those corners!
68
  *border-collapse: collapsed; // IE7 can't round corners anyway
69
  .border-radius(4px);
70
  th + th,
71
  td + td,
72
73
  th + td,
  td + th {
74
75
    border-left: 1px solid #ddd;
  }
76
77
  // Prevent a double border
  thead:first-child tr:first-child th,
78
  tbody:first-child tr:first-child th,
79
80
81
  tbody:first-child tr:first-child td {
    border-top: 0;
  }
82
  // For first th or td in the first row in the first thead or tbody
83
84
  thead:first-child tr:first-child th:first-child,
  tbody:first-child tr:first-child td:first-child {
85
86
    .border-radius(4px 0 0 0);
  }
87
88
  thead:first-child tr:first-child th:last-child,
  tbody:first-child tr:first-child td:last-child {
89
90
    .border-radius(0 4px 0 0);
  }
91
92
93
  // For first th or td in the first row in the first thead or tbody
  thead:last-child tr:last-child th:first-child,
  tbody:last-child tr:last-child td:first-child {
94
95
    .border-radius(0 0 0 4px);
  }
96
97
  thead:last-child tr:last-child th:last-child,
  tbody:last-child tr:last-child td:last-child {
98
99
    .border-radius(0 0 4px 0);
  }
Jacob Thornton's avatar
Jacob Thornton committed
100
101
}

102

103
104
105
106
// ZEBRA-STRIPING
// --------------

// Default zebra-stripe styles (alternating gray and transparent backgrounds)
107
.table-striped {
108
109
110
111
112
113
114
115
116
  tbody {
    tr:nth-child(odd) td,
    tr:nth-child(odd) th {
      background-color: #f9f9f9;
    }
  }
}


117
118
119
120
121
122
123
124
125
126
// HOVER EFFECT
// ------------
// Placed here since it has to come after the potential zebra striping
.table {
  tbody tr:hover td,
  tbody tr:hover th {
    background-color: #f5f5f5;
  }
}

127

128
129
// TABLE CELL SIZING
// -----------------
130

131
// Change the columns
132
.tableColumns(@columnSpan: 1) {
133
134
135
  float: none;
  width: ((@gridColumnWidth) * @columnSpan) + (@gridGutterWidth * (@columnSpan - 1)) - 16;
  margin-left: 0;
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
}
table {
  .span1     { .tableColumns(1); }
  .span2     { .tableColumns(2); }
  .span3     { .tableColumns(3); }
  .span4     { .tableColumns(4); }
  .span5     { .tableColumns(5); }
  .span6     { .tableColumns(6); }
  .span7     { .tableColumns(7); }
  .span8     { .tableColumns(8); }
  .span9     { .tableColumns(9); }
  .span10    { .tableColumns(10); }
  .span11    { .tableColumns(11); }
  .span12    { .tableColumns(12); }
}