_tables.scss 3.87 KB
Newer Older
1
//
2
// Basic Bootstrap table
3
//
Jacob Thornton's avatar
Jacob Thornton committed
4

5
.table {
Martijn Cuppens's avatar
Martijn Cuppens committed
6
7
8
9
10
11
12
13
  --bs-table-bg: #{$table-bg};
  --bs-table-accent-bg: transparent;
  --bs-table-striped-color: #{$table-striped-color};
  --bs-table-striped-bg: #{$table-striped-bg};
  --bs-table-active-color: #{$table-active-color};
  --bs-table-active-bg: #{$table-active-bg};
  --bs-table-hover-color: #{$table-hover-color};
  --bs-table-hover-bg: #{$table-hover-bg};
14

Jacob Thornton's avatar
Jacob Thornton committed
15
  width: 100%;
Mark Otto's avatar
Mark Otto committed
16
  margin-bottom: $spacer;
17
  color: $table-color;
18
  vertical-align: $table-cell-vertical-align;
19
20
21
22
23
24
25
26
  border-color: $table-border-color;

  // Target th & td
  // We need the child combinator to prevent styles leaking to nested tables which doesn't have a `.table` class.
  // We use the universal selectors here to simplify the selector (else we would need 6 different selectors).
  // Another advantage is that this generates less code and makes the selector less specific making it easier to override.
  // stylelint-disable-next-line selector-max-universal
  > :not(caption) > * > * {
27
    padding: $table-cell-padding;
Martijn Cuppens's avatar
Martijn Cuppens committed
28
29
    background-color: var(--bs-table-bg);
    background-image: linear-gradient(var(--bs-table-accent-bg), var(--bs-table-accent-bg));
30
    border-bottom-width: $table-border-width;
Mark Otto's avatar
Mark Otto committed
31
32
  }

33
  > tbody {
34
35
36
    vertical-align: inherit;
  }

37
  > thead {
38
    vertical-align: bottom;
39
  }
40

41
42
43
44
  // Highlight border color between thead, tbody and tfoot.
  // stylelint-disable-next-line selector-max-universal
  > :not(:last-child) > :last-child > * {
    border-bottom-color: currentColor;
45
  }
46
47
}

48

49
50
51
52
//
// Change placement of captions with a class
//

53
54
55
.caption-top {
  caption-side: top;
}
56
57


58
//
59
// Condensed table w/ half padding
60
//
61

62
.table-sm {
63
64
  // stylelint-disable-next-line selector-max-universal
  > :not(caption) > * > * {
65
    padding: $table-cell-padding-sm;
66
  }
67
68
69
}


70
// Border versions
71
//
72
// Add or remove borders all around the table and between all the columns.
73
74
75
76
77
//
// When borders are added on all sides of the cells, the corners can render odd when
// these borders do not have the same color or if they are semi-transparent.
// Therefor we add top and border bottoms to the `tr`s and left and right borders
// to the `td`s or `th`s
78

79
.table-bordered {
80
81
82
  // stylelint-disable-next-line selector-max-universal
  > :not(caption) > * {
    border-width: $table-border-width 0;
83

84
85
86
    // stylelint-disable-next-line selector-max-universal
    > * {
      border-width: 0 $table-border-width;
87
88
    }
  }
Jacob Thornton's avatar
Jacob Thornton committed
89
90
}

91
.table-borderless {
92
93
94
  // stylelint-disable-next-line selector-max-universal
  > :not(caption) > * > * {
    border-bottom-width: 0;
95
96
  }
}
97

98
// Zebra-striping
99
//
100
// Default zebra-stripe styles (alternating gray and transparent backgrounds)
101

102
.table-striped {
103
  > tbody > tr:nth-of-type(#{$table-striped-order}) {
Martijn Cuppens's avatar
Martijn Cuppens committed
104
105
    --bs-table-accent-bg: var(--bs-table-striped-bg);
    color: var(--bs-table-striped-color);
106
107
108
  }
}

109
110
111
112
113
// Active table
//
// The `.table-active` class can be added to highlight rows or cells

.table-active {
Martijn Cuppens's avatar
Martijn Cuppens committed
114
115
  --bs-table-accent-bg: var(--bs-table-active-bg);
  color: var(--bs-table-active-color);
116
}
117

118
// Hover effect
119
//
120
// Placed here since it has to come after the potential zebra striping
121

122
.table-hover {
123
  > tbody > tr:hover {
Martijn Cuppens's avatar
Martijn Cuppens committed
124
125
    --bs-table-accent-bg: var(--bs-table-hover-bg);
    color: var(--bs-table-hover-color);
126
127
128
  }
}

129

130
// Table variants
131
//
132
133
// Table variants set the table cell backgrounds, border colors
// and the colors of the striped, hovered & active tables
134

135
136
@each $color, $value in $table-variants {
  @include table-variant($color, $value);
137
}
138

139
140
// Responsive tables
//
141
142
// Generate series of `.table-responsive-*` classes for configuring the screen
// size of where your table will overflow.
143

144
145
146
147
148
149
150
151
@each $breakpoint in map-keys($grid-breakpoints) {
  $next: breakpoint-next($breakpoint, $grid-breakpoints);
  $infix: breakpoint-infix($next, $grid-breakpoints);

  @include media-breakpoint-down($breakpoint) {
    .table-responsive#{$infix} {
      overflow-x: auto;
      -webkit-overflow-scrolling: touch;
152
    }
153
  }
Mark Otto's avatar
Mark Otto committed
154
}