-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathflipcards.html
163 lines (152 loc) · 4.13 KB
/
flipcards.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel='stylesheet' href='https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css'>
<style>
.flip-card, .flip-card-click {
display: inline-block;
background-color: transparent;
width: 300px;
height: 300px;
margin-right: 12px;
margin-bottom: 12px;
border: 1px solid #f1f1f1;
perspective: 1000px;
}
.flip-card-inner {
position: relative;
width: 100%;
height: 100%;
text-align: center;
transition: transform 0.8s;
transform-style: preserve-3d;
}
.flip-card:hover .flip-card-inner,
.flip-card:focus .flip-card-inner,
.flip-card:focus-within .flip-card-inner,
.flip-card:active .flip-card-inner,
.flip-card-click:focus .flip-card-inner,
.flip-card-click:active .flip-card-inner,
.flip-card-click.flipped .flip-card-inner {
transform: rotateY(180deg);
}
.flip-card-inner:focus {
outline: 5px solid #03c23c;
cursor: pointer;
}
.flip-card-inner:hover {
outline: 5px solid #0336c2;
cursor: pointer;
}
.flip-card-front, .flip-card-back {
position: absolute;
width: 100%;
height: 100%;
display: flex;
align-items: center;
justify-content: center;
-webkit-backface-visibility: hidden; /* Safari */
backface-visibility: hidden;
}
.flip-card-front h2 {
color: white;
font-size: 16pt;
font-weight: 500;
padding: 10px;
}
.flip-card-front p, .flip-card-back p {
padding: 10px;
font-size: 16pt;
color: white;
}
.flip-card-front {
background-color: #18453b;
}
.flip-card-back {
background-color: #008183;
transform: rotateY(180deg);
}
</style>
<title>Flip Cards</title>
</head>
<body>
<div class="container-fluid">
<div class="col-sm-10 offset-sm-1">
<h1>Flip Cards</h1>
<p>If adding images on front side, still use heading with Bootstrap class of sr-only to add text so that screen readers will include it in list of headings.</p>
<h2>Hover, Tap, or Tab to Flip the Card (CSS Only)</h2>
<!-- Flip card headings should be changed to respect page hierarchy -->
<div class="flip-card">
<div class="flip-card-inner" tab-index="0">
<div class="flip-card-front">
<h2>Card 1 Front</h2>
</div>
<div class="flip-card-back">
<p>Card 1 Back</p>
</div>
</div>
</div>
<div class="flip-card">
<div class="flip-card-inner" tab-index="0">
<div class="flip-card-front">
<h2>Card 2 Front</h2>
</div>
<div class="flip-card-back">
<p>Card 2 Back</p>
</div>
</div>
</div>
<div class="flip-card">
<div class="flip-card-inner" tab-index="0">
<div class="flip-card-front">
<h2>Card 3 Front</h2>
</div>
<div class="flip-card-back">
<p>Card 3 Back</p>
</div>
</div>
</div>
<h2>Click, Tap, or Tab+Enter to Flip the Card (Uses JS)</h2>
<div class="flip-card-click">
<div class="flip-card-inner" tab-index="0">
<div class="flip-card-front">
<h2>Card 1 Front</h2>
</div>
<div class="flip-card-back">
<p>Card 1 Back</p>
</div>
</div>
</div>
<div class="flip-card-click">
<div class="flip-card-inner" tabindex="0">
<div class="flip-card-front">
<h2>Card 2 Front</h2>
</div>
<div class="flip-card-back">
<p>Card 2 Back</p>
</div>
</div>
</div>
<div class="flip-card-click">
<div class="flip-card-inner" tab-index="0">
<div class="flip-card-front">
<h2>Card 3 Front</h2>
</div>
<div class="flip-card-back">
<p>Card 3 Back</p>
</div>
</div>
</div>
</div>
</div>
<script>
document.querySelectorAll('.flip-card-click .flip-card-inner').forEach(function(item) {
item.addEventListener('keypress', function(evt) { if (evt.keyCode == 13 || evt.keyCode == 32) { item.click(); } });
});
document.querySelectorAll('.flip-card-click').forEach(function(item) {
item.addEventListener('click', function () { this.classList.toggle('flipped'); });
});
</script>
</body>
</html>