|
2 | 2 | //------------------------------------------------ |
3 | 3 | //------------------------------------------------ |
4 | 4 |
|
| 5 | +// dynamic tab switching based on https: //levelup.gitconnected.com/tabbed-interfaces-without-javascript-661bab1eaec8 |
| 6 | + |
5 | 7 | .nav-tab { |
6 | 8 | border-bottom: $base-border-gray; |
7 | 9 | @include display(flex); |
|
10 | 12 |
|
11 | 13 | .item-tab { |
12 | 14 |
|
| 15 | + label, |
13 | 16 | a { |
14 | 17 | transition: none; // do not animate the transition to active |
15 | 18 | color: $base-font-color-light; |
|
27 | 30 | &:hover { |
28 | 31 | cursor: pointer; |
29 | 32 | } |
| 33 | + } |
30 | 34 |
|
31 | | - &.active { |
32 | | - border-bottom: 2px solid $brand-primary; |
33 | | - padding: 0 20px 8px; // so text does not jump up when active |
34 | | - color: $brand-primary; |
35 | | - pointer-events: none; |
36 | | - } |
| 35 | + label { |
| 36 | + -webkit-touch-callout: none; |
| 37 | + -webkit-user-select: none; |
| 38 | + -khtml-user-select: none; |
| 39 | + -moz-user-select: none; |
| 40 | + -ms-user-select: none; |
| 41 | + user-select: none; |
37 | 42 | } |
38 | 43 |
|
39 | 44 | } |
|
42 | 47 | @include justify-content(space-between); |
43 | 48 |
|
44 | 49 | .item-tab { |
| 50 | + label, |
45 | 51 | a { |
46 | 52 | transition: none; // do not animate the transition to active |
47 | 53 | padding: 0 10px 10px; |
|
51 | 57 | } |
52 | 58 | } |
53 | 59 |
|
| 60 | +.nav-tab>.item-tab>a.active, // used in the blog |
| 61 | +.tabsection>input:nth-child(1):checked~.nav-tab .item-tab:nth-child(1) label, |
| 62 | +.tabsection>input:nth-child(2):checked~.nav-tab .item-tab:nth-child(2) label, |
| 63 | +.tabsection>input:nth-child(3):checked~.nav-tab .item-tab:nth-child(3) label, |
| 64 | +.tabsection>input:nth-child(4):checked~.nav-tab .item-tab:nth-child(4) label, |
| 65 | +.tabsection>input:nth-child(5):checked~.nav-tab .item-tab:nth-child(5) label, |
| 66 | +.tabsection>input:nth-child(6):checked~.nav-tab .item-tab:nth-child(6) label, |
| 67 | +.tabsection>input:nth-child(7):checked~.nav-tab .item-tab:nth-child(7) label, |
| 68 | +.tabsection>input:nth-child(8):checked~.nav-tab .item-tab:nth-child(8) label, |
| 69 | +.tabsection>input:nth-child(9):checked~.nav-tab .item-tab:nth-child(9) label { |
| 70 | + border-bottom: 2px solid $brand-primary; |
| 71 | + padding: 0 20px 8px; // so text does not jump up when active |
| 72 | + color: $brand-primary; |
| 73 | + pointer-events: none; |
| 74 | +} |
| 75 | + |
54 | 76 | .tabsection { |
55 | 77 | border-bottom: $base-border-gray; |
56 | 78 | border-left: $base-border-gray; |
|
67 | 89 | list-style: none; |
68 | 90 | } |
69 | 91 | } |
70 | | -} |
71 | 92 |
|
72 | | -.tabcontent { |
73 | | - display: none; |
| 93 | + input { // hide the input because they are not interactive |
| 94 | + display: block; /* "enable" hidden elements in IE/edge */ |
| 95 | + position: absolute; /* then hide them off-screen */ |
| 96 | + left: -100%; |
| 97 | + } |
74 | 98 |
|
75 | | - &.active { |
76 | | - display: block; |
| 99 | + .tabcontent { |
| 100 | + section { // by default, hide all sections until the user clicks on the associated label |
| 101 | + position: absolute; |
| 102 | + top: -999em; |
| 103 | + left: -999em; |
| 104 | + } |
77 | 105 | } |
78 | 106 | } |
| 107 | + |
| 108 | +.tabsection>input:nth-child(1):checked~.tabcontent section:nth-child(1), |
| 109 | +.tabsection>input:nth-child(2):checked~.tabcontent section:nth-child(2), |
| 110 | +.tabsection>input:nth-child(3):checked~.tabcontent section:nth-child(3), |
| 111 | +.tabsection>input:nth-child(4):checked~.tabcontent section:nth-child(4), |
| 112 | +.tabsection>input:nth-child(5):checked~.tabcontent section:nth-child(5), |
| 113 | +.tabsection>input:nth-child(6):checked~.tabcontent section:nth-child(6), |
| 114 | +.tabsection>input:nth-child(7):checked~.tabcontent section:nth-child(7), |
| 115 | +.tabsection>input:nth-child(8):checked~.tabcontent section:nth-child(8), |
| 116 | +.tabsection>input:nth-child(9):checked~.tabcontent section:nth-child(9) { |
| 117 | + position: static; |
| 118 | +} |
0 commit comments