Skip to content

Commit 6408a9a

Browse files
committed
Completed exercise 05
1 parent 7619c73 commit 6408a9a

File tree

1 file changed

+158
-0
lines changed

1 file changed

+158
-0
lines changed

05 - Flex Panel Gallery/index.html

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>Flex Panels 💪</title>
6+
<link href='https://fonts.googleapis.com/css?family=Amatic+SC' rel='stylesheet' type='text/css'>
7+
</head>
8+
<body>
9+
<style>
10+
html {
11+
box-sizing: border-box;
12+
background:#ffc600;
13+
font-family:'helvetica neue';
14+
font-size: 20px;
15+
font-weight: 200;
16+
}
17+
body {
18+
margin: 0;
19+
}
20+
*, *:before, *:after {
21+
box-sizing: inherit;
22+
}
23+
24+
.panels {
25+
min-height:100vh;
26+
overflow: hidden;
27+
display:flex;
28+
}
29+
30+
.panel {
31+
background:#6B0F9C;
32+
box-shadow:inset 0 0 0 5px rgba(255,255,255,0.1);
33+
color:white;
34+
text-align: center;
35+
align-items:center;
36+
/* Safari transitionend event.propertyName === flex */
37+
/* Chrome + FF transitionend event.propertyName === flex-grow */
38+
transition:
39+
font-size 0.7s cubic-bezier(0.61,-0.19, 0.7,-0.11),
40+
flex 0.7s cubic-bezier(0.61,-0.19, 0.7,-0.11),
41+
background 0.2s;
42+
font-size: 20px;
43+
background-size:cover;
44+
background-position:center;
45+
flex: 1; /*evenly distribute extra space*/
46+
/*justify-content:center;
47+
align-items: center; Neither of these properties are required because the CSS properties of the nested flex items are doing all the work*/
48+
display:flex;
49+
flex-direction: column; /*makes the text stack vertically rather than ltr*/
50+
}
51+
52+
.panel > *:first-child {
53+
transform: translateY(-100%);
54+
}
55+
56+
.panel.open-active> *:first-child {
57+
transform: translateY(0%);
58+
}
59+
60+
.panel > *:last-child {
61+
transform: translateY(100%);
62+
}
63+
64+
.panel.open-active> *:last-child {
65+
transform: translateY(0%);
66+
}
67+
68+
69+
.panel1 { background-image:url(https://source.unsplash.com/gYl-UtwNg_I/1500x1500); }
70+
.panel2 { background-image:url(https://source.unsplash.com/1CD3fd8kHnE/1500x1500); }
71+
.panel3 { background-image:url(https://images.unsplash.com/photo-1465188162913-8fb5709d6d57?ixlib=rb-0.3.5&q=80&fm=jpg&crop=faces&cs=tinysrgb&w=1500&h=1500&fit=crop&s=967e8a713a4e395260793fc8c802901d); }
72+
.panel4 { background-image:url(https://source.unsplash.com/ITjiVXcwVng/1500x1500); }
73+
.panel5 { background-image:url(https://source.unsplash.com/3MNzGlQM7qs/1500x1500); }
74+
75+
.panel > * {
76+
margin:0;
77+
width: 100%;
78+
transition:transform 0.5s;
79+
border: 1px solid red;
80+
flex: 1 0 auto; /*forces each element to take up 1/nth of the container*/
81+
display: flex;
82+
justify-content: center; /*used with flex. Determines the horizontal placement of content within the element*/
83+
align-items: center; /* used with flex. Determines the vertical placement of content within the element. In this examples the content within the <p> tags will be centered*/
84+
}
85+
86+
.panel p {
87+
text-transform: uppercase;
88+
font-family: 'Amatic SC', cursive;
89+
text-shadow:0 0 4px rgba(0, 0, 0, 0.72), 0 0 14px rgba(0, 0, 0, 0.45);
90+
font-size: 2em;
91+
}
92+
.panel p:nth-child(2) {
93+
font-size: 4em;
94+
}
95+
96+
.panel.open {
97+
flex:5; /*when it has a class of open, take 5 times the amount space as something with flex:1;*/
98+
font-size:40px;
99+
}
100+
101+
.cta {
102+
color:white;
103+
text-decoration: none;
104+
}
105+
106+
</style>
107+
108+
109+
<div class="panels">
110+
<div class="panel panel1">
111+
<p>Hey</p>
112+
<p>Let's</p>
113+
<p>Dance</p>
114+
</div>
115+
<div class="panel panel2">
116+
<p>Give</p>
117+
<p>Take</p>
118+
<p>Receive</p>
119+
</div>
120+
<div class="panel panel3">
121+
<p>Experience</p>
122+
<p>It</p>
123+
<p>Today</p>
124+
</div>
125+
<div class="panel panel4">
126+
<p>Give</p>
127+
<p>All</p>
128+
<p>You can</p>
129+
</div>
130+
<div class="panel panel5">
131+
<p>Life</p>
132+
<p>In</p>
133+
<p>Motion</p>
134+
</div>
135+
</div>
136+
137+
<script>
138+
139+
const panels = document.querySelectorAll(".panel");
140+
function toggleOpen() {
141+
this.classList.toggle("open");
142+
}
143+
144+
function toggleActive(e) {
145+
if(e.propertyName.includes('flex')) {
146+
this.classList.toggle("open-active");
147+
}
148+
}
149+
150+
panels.forEach(panel => panel.addEventListener('click',toggleOpen));
151+
panels.forEach(panel => panel.addEventListener('transitionend',toggleActive));
152+
153+
</script>
154+
155+
156+
157+
</body>
158+
</html>

0 commit comments

Comments
 (0)