Coding Challenge SOLUTION #8 - Flash Cards
Skills:
HTML & CSS80%
Key Takeaways
The video demonstrates a solution to a coding challenge involving flash cards, utilizing CSS styling, Flexbox, and 3D transformations to create a flipping effect on a card.
Full Transcript
okay then so the first thing I'd like to do is attach an event listener to this card div right here a click event listener so that when we click on that card it toggles another class which will be flipped and then we can use that class to style the card to show either the front or the back later so let me go to the index.js file to do this we need a constant we'll call it card and we set it equal to documents dot oh we need to spell this correctly documents dot query select all and this is going to be the div with a class of card okay so let's take that card and add an event listener to it which will be a click event and when that occurs we fire a function and inside that function we just want to take our card get the class list and we want to toggle a particular class and that will be flipped so let's check this out in a browser if I inspect this we should see if I click on it see this element over here this one if I click on this it gets a class of flipped yep and if I click again it takes that class away awesome so now we have that conditional class and we can go ahead and start styling the card based on that class first of all I want to apply some very very simple Styles so I've got this little comment down here for the solution and what I'd like to do first of all is just style the front and back of the card so let's go back over here and do that so what we'll do is grab both the front and the back at once and star them together because there's going to be a lot of common styles for these the first thing we want to do is position this absolutely so position absolute and that's absolutely relative to the parent element card because that's position relative Now the default values for its position are going to be 0 and 0 in the top left we don't have to manually type those out so next I will say the width of this is 100 of the parent and the height is 100 of the parent as well so 300 pixels for both then what I'll do is say the background color of the front and the back is going to be 222 which is a dark gray will also apply a border radius which is going to be 8 pixels to soften those Corners a border as well which is going to be two pixels solid and white so FFF and then after that the cursor is going to be pointer so if we take a look at this should start to look a little bit better awesome now I want this text to appear down here and by the way we're only seeing one of the cards now well we're just seeing the back of the card and not the front and the reason we're just seeing the back is because they're on top of each other now because we positioned them both absolutely so they stack on top of each other and because this comes after this one in the document this one has a higher stacking order by default so it shows on top of the front anyway what I'd like to do is position the text for both of these in the middle down here now there's a little trick we can use to do this and that is to display these as Flex first of all because then we can say that the flex Direction is going to be in the column so going down and then we can use justify content to say Center and that will put it in the center of the card so if we take a look now we can see it's in the middle awesome all right so now we've done that next I want to maybe show the front by default instead of the back now the way we're going to do this is by rotating the back so that we can't see it and instead we see the front so let me quickly show you this I'm going to come down here and say okay I want to grab now just the back and the color of this first of all of this text will be like a golden color just to distinguish it a little bit so DB and then C A and then six C save that in preview now we can see we've got a gold color for this text then I will say transform and it will be a rotate around the y-axis now the y-axis is the axis going up and down so this way like that so if we rotate around that it's going to look like it's flipping so for example if I rotate it by 25 degrees you'll see a very slight flip it actually just looks like it's getting squashed but it is flipping around that y-axis but you can see the front of the card underneath it now so what we need to do is take it all the way to 180 degrees to turn it around now when we do that look at what happens well we just see the back of the back of the card if that makes sense so we see Ninja fledgling but a mirror image of this because it's flipped 180 degrees so essentially we're seeing the back of the back does that make sense and we don't want to see the back of the back now what we can do is hide this using a property called back face visibility so if we set that to Hidden whenever an element is rotated 180 degrees then we don't see it because it's hidden when we see the back face so now we should just see yep the front underneath because this is turned 180 degrees if we change this to zero again then because we're not showing the back it will be visible but we are showing the back when we say 180 degrees so it's hidden and we see the front of the card underneath awesome okay so now what I'd like to do is react to that conditional class remember when we click on this card we want to turn it around now if we take a look at this card when we click on this it's toggling that flipped class now we want to style it differently when we have that flipped class because we want to show the back of the card don't we that other promo code instead so what we're going to do is we're going to just paste in this and it says okay when the card has a class of flipped then I want to transform and it's going to rotate around the y direction the whole card this is so not just the front or back remember the back is already rotated 180 degrees so the whole card is going to be rotated by 180 degrees and also what I want to do is come up here and select the card itself even without the flipped class so all of the time and we want to apply a transition property to the transform which is what we just specified right here and we want it to be over 0.5 seconds and that's so it doesn't just rotate like a snap without any kind of Animation we want a transition so it looks nice over 0.5 seconds so let me save this and come back over here now watch what happens when I click on this well I click on that and now we just see the back of the front of the card now remember for the back of the card we said for back face visibility it's going to be hidden so when we rotate the back we don't see it however we don't do that on the front and we're not actually rotating the front when we click on the card we're rotating the card itself so even if we apply this to the front it wouldn't work and it's not going to work if we apply it to the card itself oops let me undo that if we took this thing right here and applied it to the card that's not going to work either because then we would only ever see the front of the card right so we can't do it right here either so the way we get around this is by using a property called transform style and we set that to preserve 3D and that will sort it out for us so now this should work and if we click on this we're going to see the back and then we see the front then we see the back and the front so this is working but it doesn't yet look fully 3D now the way we can combat this is by using a perspective property on whatever the parent of this element is now the parent of that element is the section right here so I could take the section and I could apply a property of perspective and we would set that to a number I like to use something around 900 pixels now if I save this when I click on this it's going to look a little more 3D because we have that perspective so click on it and that looks a little bit better right awesome it's all working now the bigger this number so if I do something like 5000 then the smaller the 3d effect is going to be and it's barely noticeable there still quite good but barely noticeable if I go up to ten thousand it's going to be less of an effect now if I go something really low like 100 it's going to be a really exaggerated 3d effect like that which we don't want to do so I like to go somewhere in the middle ground I like about 900 pixels and then we get that nice 3d effect awesome so there we go my friends that is the solution so hopefully you managed to do this as well it doesn't have to be the way that I did it it could have been entirely your own way if you've got a different way feel free to share your solution Down Below in the comments [Music]
Original Description
📂🥷🏼 Access the solution files on GitHub:
https://github.com/iamshaunjp/Coding-Challenges/tree/challenge-8-solution
🚀🥷🏼 Get access to all free & PREMIUM courses on Net Ninja Pro:
https://net-ninja-pro.teachable.com/p/net-ninja-pro/
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from Net Ninja · Net Ninja · 0 of 60
← Previous
Next →
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
Regular Expressions (RegEx) Tutorial #14 - Matching a Username
Net Ninja
Regular Expressions (RegEx) Tutorial #15 - Email RegEx Pattern
Net Ninja
Regular Expressions (RegEx) Tutorial #16 - Finishing Touches
Net Ninja
GraphQL Tutorial #1 - Introduction to GraphQL
Net Ninja
GraphQL Tutorial #2 - A Birdseye View of GraphQL
Net Ninja
GraphQL Tutorial #3 - Project (stack) Overview
Net Ninja
GraphQL Tutorial #4 - Making Queries (front-end preview)
Net Ninja
GraphQL Tutorial #5 - Express App Setup
Net Ninja
GraphQL Tutorial #6 - Setting up GraphQL
Net Ninja
GraphQL Tutorial #7 - GraphQL Schema
Net Ninja
GraphQL Tutorial #8 - Root Query
Net Ninja
GraphQL Tutorial #9 - The Resolve Function
Net Ninja
GraphQL Tutorial #10 - Testing Queries in Graphiql
Net Ninja
GraphQL Tutorial #11 - GraphQL ID Type
Net Ninja
GraphQL Tutorial #12 - Author Type
Net Ninja
GraphQL Tutorial #13 - Type Relations
Net Ninja
GraphQL Tutorial #14 - GraphQL Lists
Net Ninja
GraphQL Tutorial #15 - More on Root Queries
Net Ninja
GraphQL Tutorial #16 - Connecting to mLab
Net Ninja
GraphQL Tutorial #17 - Mongoose Models
Net Ninja
GraphQL Tutorial #18 - Mutations
Net Ninja
GraphQL Tutorial #19 - More on Mutations
Net Ninja
GraphQL Tutorial #20 - Updating the Resolve Functions
Net Ninja
GraphQL Tutorial #21 - GraphQL NonNull
Net Ninja
GraphQL Tutorial #22 - Adding a Front-end
Net Ninja
GraphQL Tutorial #23 - Create React App
Net Ninja
GraphQL Tutorial #24 - Book List Component
Net Ninja
GraphQL Tutorial #25 - Apollo Client Setup
Net Ninja
GraphQL Tutorial #26 - Making Queries from React
Net Ninja
GraphQL Tutorial #27 - Rendering Data in a Component
Net Ninja
GraphQL Tutorial #28 - Add Book Component
Net Ninja
GraphQL Tutorial #29 - External Query File
Net Ninja
GraphQL Tutorial #30 - Updating Component State
Net Ninja
GraphQL Tutorial #31 - Composing Queries
Net Ninja
GraphQL Tutorial #32 - query variables
Net Ninja
GraphQL Tutorial #33 - Re-fetching Queries
Net Ninja
GraphQL Tutorial #34 - Book Details Component
Net Ninja
GraphQL Tutorial #36 - Styling the App
Net Ninja
GraphQL Tutorial #35 - Making a Single Query
Net Ninja
Build Apps with Vue & Firebase - Udemy Course
Net Ninja
Updated Vue & Firebase Course (Udemy)
Net Ninja
Vue & Firebase Real-time Chat (Preview) #1 - Intro
Net Ninja
Vue & Firebase Real-time Chat (Preview) #2 - Project Structure
Net Ninja
Vue & Firebase Real-time Chat (Preview) #3 - Firestore Setup
Net Ninja
Vue & Firebase Real-time Chat (Preview) #4 - Welcome Screen
Net Ninja
Vue & Firebase Real-time Chat (Preview) #5 - Props in Routes
Net Ninja
Vue & Firebase Real-time Chat (Preview) #6 - Route Guards
Net Ninja
Vue & Firebase Real-time Chat (Preview) #7 - Chat Window
Net Ninja
Vue & Firebase Real-time Chat (Preview) #8 - New Message Component
Net Ninja
Object Oriented JavaScript Tutorial #1 - Introduction
Net Ninja
Object Oriented JavaScript Tutorial #2 - Object Literals
Net Ninja
Object Oriented JavaScript Tutorial #3 - Updating Properties
Net Ninja
Object Oriented JavaScript Tutorial #4 - Classes
Net Ninja
Object Oriented JavaScript Tutorial #5 - Class Constructors
Net Ninja
Object Oriented JavaScript Tutorial #6 - Class Methods
Net Ninja
Object Oriented JavaScript Tutorial #7 - Method Chaining
Net Ninja
Object Oriented JavaScript Tutorial #8 - Class Inheritance
Net Ninja
Object Oriented JavaScript Tutorial #9 - Constructors (under the hood)
Net Ninja
Object Oriented JavaScript Tutorial #10 - Prototype
Net Ninja
Object Oriented JavaScript Tutorial #11 - Prototype Inheritance
Net Ninja
More on: HTML & CSS
View skill →Related Reads
📰
📰
📰
📰
Bloom Filters, Explained Properly
Dev.to · Daksh Gargas
Prefix Sums: The Preprocessing Trick That Makes Range Queries Instant
Medium · Programming
I Thought I Was Ready for the Interview — Then One Simple Math Question Destroyed Me
Medium · Programming
Week 2(Day 10): LeetCode Two Pointers(slow & fast): Remove Duplicates from Sorted Array (Brute…
Medium · Python
🎓
Tutor Explanation
DeepCamp AI