tables.less 4.32 KB
Newer Older
1
//
2
3
// Tables
// --------------------------------------------------
Jacob Thornton's avatar
Jacob Thornton committed
4

5

6
table {
7
  background-color: @table-bg;
8
}
9
10
11
th {
  text-align: left;
}
12
13


14
// Baseline styles
Jacob Thornton's avatar
Jacob Thornton committed
15

16
.table {
Jacob Thornton's avatar
Jacob Thornton committed
17
  width: 100%;
18
  max-width: 100%;
19
  margin-bottom: @line-height-computed;
20
  // Cells
21
22
23
  > thead,
  > tbody,
  > tfoot {
24
25
26
    > tr {
      > th,
      > td {
27
        padding: @table-cell-padding;
28
29
30
31
32
        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
    border-bottom: 2px solid @table-border-color;
38
39
  }
  // Remove top border from thead by default
40
41
42
43
44
45
  > caption + thead,
  > colgroup + thead,
  > thead:first-child {
    > tr:first-child {
      > th,
      > td {
46
47
48
        border-top: 0;
      }
    }
49
50
  }
  // Account for multiple tbody instances
51
  > tbody + tbody {
52
    border-top: 2px solid @table-border-color;
53
  }
Mark Otto's avatar
Mark Otto committed
54
55
56

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

61

62
// Condensed table w/ half padding
63

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


78
// Bordered version
79
80
//
// Add borders all around the table and between all the columns.
81

82
.table-bordered {
83
  border: 1px solid @table-border-color;
84
  > thead,
85
86
  > tbody,
  > tfoot {
87
88
89
    > tr {
      > th,
      > td {
90
        border: 1px solid @table-border-color;
91
      }
liuyl's avatar
liuyl committed
92
    }
93
  }
94
95
96
97
  > thead > tr {
    > th,
    > td {
      border-bottom-width: 2px;
98
99
    }
  }
Jacob Thornton's avatar
Jacob Thornton committed
100
101
}

102

103
// Zebra-striping
104
//
105
// Default zebra-stripe styles (alternating gray and transparent backgrounds)
106

107
108
.table-striped {
  > tbody > tr:nth-child(odd) {
109
    background-color: @table-bg-accent;
110
111
112
113
  }
}


114
// Hover effect
115
//
116
// Placed here since it has to come after the potential zebra striping
117

118
119
.table-hover {
  > tbody > tr:hover {
120
    background-color: @table-bg-hover;
121
122
123
  }
}

124

125
// Table cell sizing
126
//
127
// Reset default table behavior
128

boomsb's avatar
boomsb committed
129
table col[class*="col-"] {
130
  position: static; // Prevent border hiding in Firefox and IE9/10 (see https://github.com/twbs/bootstrap/issues/11623)
131
132
133
  float: none;
  display: table-column;
}
134
table {
135
136
  td,
  th {
boomsb's avatar
boomsb committed
137
    &[class*="col-"] {
138
      position: static; // Prevent border hiding in Firefox and IE9/10 (see https://github.com/twbs/bootstrap/issues/11623)
139
140
141
142
      float: none;
      display: table-cell;
    }
  }
143
144
}

145

146
// Table backgrounds
147
//
148
149
// Exact selectors below required to override `.table-striped` and prevent
// inheritance to nested tables.
150

151
// Generate the contextual variants
Zlatan Vasović's avatar
Zlatan Vasović committed
152
153
.table-row-variant(active; @table-bg-active);
.table-row-variant(success; @state-success-bg);
154
.table-row-variant(info; @state-info-bg);
Zlatan Vasović's avatar
Zlatan Vasović committed
155
.table-row-variant(warning; @state-warning-bg);
156
.table-row-variant(danger; @state-danger-bg);
157
158
159
160


// Responsive tables
//
161
// Wrap your tables in `.table-responsive` and we'll make them mobile friendly
162
163
164
// by enabling horizontal scrolling. Only applies <768px. Everything above that
// will display normally.

165
.table-responsive {
166
  @media screen and (max-width: @screen-xs-max) {
167
    width: 100%;
168
    margin-bottom: (@line-height-computed * 0.75);
169
    overflow-y: hidden;
170
    overflow-x: auto;
171
    -ms-overflow-style: -ms-autohiding-scrollbar;
172
    border: 1px solid @table-border-color;
173
    -webkit-overflow-scrolling: touch;
174

175
    // Tighten up spacing
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
    > .table {
      margin-bottom: 0;

      // Ensure the content doesn't wrap
      > thead,
      > tbody,
      > tfoot {
        > tr {
          > th,
          > td {
            white-space: nowrap;
          }
        }
      }
    }

    // Special overrides for the bordered tables
    > .table-bordered {
      border: 0;

      // Nuke the appropriate borders so that the parent can handle them
      > thead,
      > tbody,
      > tfoot {
        > tr {
          > th:first-child,
          > td:first-child {
            border-left: 0;
          }
          > th:last-child,
          > td:last-child {
            border-right: 0;
          }
        }
210
211
212
213
214
215
216
      }

      // Only nuke the last row's bottom-border in `tbody` and `tfoot` since
      // chances are there will be only one `tr` in a `thead` and that would
      // remove the border altogether.
      > tbody,
      > tfoot {
217
218
219
220
221
222
223
        > tr:last-child {
          > th,
          > td {
            border-bottom: 0;
          }
        }
      }
224

225
226
227
    }
  }
}