Placeholder Image

Subtitles section Play video

  • Hello, everybody.

  • Welcome back to see us as three in 30 days.

  • Today is day 18 and we're gonna be coding up some CSS three tool tips.

  • Let me show you what that looks like.

  • Right here in the browser.

  • We have the final result down here, and the tool tip is essentially a little element that just appears in some position around the element toe let you know a little bit more information.

  • The purpose of a tool tip is not to look fancy but specifically to help the user understand something about what they are interacting with.

  • So from a usability standpoint, let's say this little pink box I have here is an acronym and you want to be able to let them know what that acronym stands for.

  • When you hover over, it may be the tool tip lets them know what it stands for.

  • Or maybe there is an element called to action where if you hover over it, it lets them know additional information to help them understand how to interact with that element a little bit better.

  • There's an endless amount of reasons why you might want a tool tip, but the purpose of this lesson is not necessarily to show you the y of the tool tip.

  • Rather the how to make a tool tip.

  • So let's jump in and start making tool tips.

  • So in this final results, I'm just gonna show you what we're gonna make.

  • We got this top tool tip this right tool tip, bottom tool tip and left tool tip.

  • All we're gonna do is we're gonna code out these thes little elements.

  • It's just something to hover over, and then we're gonna make a global tool tip style, and then we're going to start positioning them, depending on where you hover all in CSS.

  • That's the exciting part about this.

  • Ah, lot of the Times tool tips are made using JavaScript.

  • Urge a query, but in this case, just CSS three.

  • Because that's how we roll in CSS three and 30 days.

  • Over here in the code editor, we have our 18 tool tips.

  • Take a moment to go and download that and open up your index and sandbox.

  • Final Nazi SS is always there for your reference as you go along.

  • If you mess something up or if you confused about something that should help you out.

  • Otherwise, let's get started here in the index.

  • I'm gonna show you what the mark up looks like because it is a little bit important because we're gonna be styling it.

  • So in the sandbox here we have just some dibs on the div.

  • They all have the class of tool tip and then the position of where it will be.

  • So the class simply top right bottom and left.

  • They all have the class of tool tip.

  • The other thing is there is a title attribute with some text.

  • I've just said to tool tip on top, right, and so on and so forth.

  • And that is really it.

  • For the markup in the sandbox, we're gonna get started.

  • And we're gonna style our tool tip element itself so that the target that we want to hover over So we're going to select tool tip, and then we're just going to say position relative.

  • This is important because we're gonna be positioning that tool tip itself.

  • So right now we're positioning the parent element that we call tool tip, but it has to have a position of relative or absolute, whichever one you choose in this case, we're gonna use relative so it doesn't move around in weird places.

  • And that's simply so that when we position the tool tip itself using the before and after virtual elements, we need to have it stay contained within its parent.

  • So position relativism.

  • Very important in this case.

  • Height 60 pixels.

  • Again, this is just the target we're gonna hover over.

  • I'm just jamming here.

  • 250 pixels background.

  • We're gonna use the pink color that branded pink.

  • That's f 2395 A.

  • Whatever color you want really?

  • Doesn't matter.

  • This isn't functionality.

  • This is just some.

  • This is just vanity styles.

  • Here, text aligns center.

  • We're gonna line height the text in the center of it to 60 pixels, which is gonna be the same as the height.

  • So it's vertically aligned as well.

  • A center line because of text line, center font size, something large and readable.

  • Aging pixels.

  • Margin zero auto.

  • And that's how you style a target element.

  • Boom.

  • Just like that.

  • Nice.

  • Okay, let's go back to the the little little little sandbox here, and let's get coating up the tool tip itself.

  • So we're going to just say tool tip, But we're gonna actually select the before pseudo elements.

  • This whole time I've been calling them virtual elements.

  • I think I made that up.

  • Maybe I didn't.

  • But the idea is that it is a pseudo element.

  • It's not a real element.

  • It's kind of an element that doesn't really appear unless you make it do something.

  • So it's just a funky little CSS trick again.

  • I've been calling them virtual elements this this whole time, and I think I made that up.

  • But we still got the job done.

  • Right, Brad?

  • Right, Brad.

  • Position.

  • We're gonna position Absolute because we want to move that around freely outside of the flow.

  • We don't really want position relative to be messing with it.

  • So position absolutes gonna give us more flexibility that index to just a little bit above the default, which to tool tip will be at zero, and then this one will bring it up just a little bit.

  • We don't want it to be behind its parent element display None by default, with 200 pixels padding 10 pixels.

  • So something nice and simple font size.

  • I'm gonna go 0.8.

  • That's 80% of the parent elements font size, which is 18 pixels.

  • So 80% of the 80% of that, whatever whatever that number is.

  • Line height 1.4 em.

  • Let's try that.

  • And border radius, we're going to say five pixels, slightly rounded background color.

  • We're gonna go with an RGB a something that you could see through simply a 000 and 0.8.

  • So it's black, but 80% Alfa Channel.

  • So little bit transparent color white.

  • That's the text.

  • The content.

  • This is cool content used with the before and after Sudan elements to generate content specific text within an element.

  • So we've been using this a lot in this way, but they're actually gonna This means you can actually put text within the element.

  • We just putting an empty string because it allows that after element to appear.

  • So we still need to have content within the pseudo element.

  • But we're actually gonna have a display riel content this time, not just an empty string.

  • So we're just gonna do something fun here.

  • So instead of an empty string rocks, you're gonna use attributes value.

  • This says attributes value for the content property.

  • So this is specific a specific value for this property, which means we have access to within this parentheses a specific attributes within the HTML.

  • So we want to grab the title.

  • That title we specifically put in the HTML will say Tool tip on the right told upon the bottom, so on and so forth.

  • So that is cool dynamic.

  • It's not just hard coded.

  • So this will depend on whatever the title is of that element.

  • Really exciting stuff.

  • I'm so pumped.

  • Okay, were announced selectable tip after pseudo element.

  • And now, before we get move forward, let's actually just see if this did anything.

  • So I'm gonna move over to the browser and it doesn't do anything because we haven't done any styles upon hover.

  • So we're gonna work on that.

  • Let me, Actually, let's just do that now So we can, so we can make it appear so tool tip hover.

  • And then the before.

  • So how that works is the tool tip.

  • Ah, the Toyota element.

  • When we hover over the tool tip element, do something with the before pseudo element.

  • So it's a kind of an interesting little selector, So display in line block.

  • Watch this.

  • Say that Now when I hover, nothing happens exactly what I wanted.

  • Now you might be wondering why that little thing pops up when you say that's just the title attribute appearing by default the browsers need of functionality.

  • It shows, uh, the title just for accessibility.

  • But we will actually want to make our own so back to the original problem.

  • We don't see it.

  • I'm thinking that's because, okay, Super silly.

  • Just realized this I was styling.

  • Here's the problem.

  • Maybe you notice this and you were just shaking your head wondering when I was gonna catch it.

  • I styled tool tip after Suitor Element.

  • I meant to style these tool tip before pseudo element.

  • And then down here, I said on, however, show that before element, which we haven't done anything with.

  • So let's change that to before and top.

  • We're going to take that out because I'm actually gonna use that.

  • Save that and then on hover, that should work.

  • Let's see what happens here.

  • There it iss Okay, so the tool tip on top appears there.

  • It's at the very it's somewhere in the top, right?

  • I don't really know what's going on with its position so we need to fix that.

  • Plus, we need to do one little thing.

  • I want to show a little arrow pointing towards the element itself.

  • So down here in the final example, I want it to look like that has a little arrow.

  • So I'm gonna create that little arrow with, ah, the after pseudo element, which I was accidentally styling this whole time.

  • So that's gonna be like this position, Absolute Zet Index, We're gonna say one, it's gonna be above the parent, but behind the the little tool tip itself And then I'm gonna say display none again.

  • By default, we don't associate with zero height zero, and this is because we're gonna make it.

  • We're gonna make a triangle out of a border like we did with Pac Man just recently here.

  • So we're gonna say border five pixels.

  • Solid, transparent.

  • So we don't see any of the border, and then a little bit later here, I'm gonna create and display one side of it.

  • So let's just leave it at that and they're gonna say, content, empty string.

  • So that will create an element that we still won't see.

  • And we're gonna do something within a SEC.

  • So let's position that.

  • Let's, um, let's say article bottom zero No, 100%.

  • So the very bottom of the element left 50% border top color.

  • Let's do the same color as the tool.

  • Tip 0000 point.

  • Foz your 0.0.8 rgb a.

  • Let's say that and see what just happened.

  • Okay, so I don't see it, and that is because we're actually on hover up here.

  • Where are we?

  • Right here.

  • We need to make the after pseudo element appear on hovers.

  • Well, tool tip hover after, So save that.

  • But I'm going to put this style after that hover simply because it's cascading.

  • I don't want the staff to be before this, just in case there's some sort of problem.

  • Okay, so something is happening here.

  • So when I hover now, you can see the arrow.

  • It's the right Sape shape and size, but it's in the wrong spot, so we need to move that in the right spot.

  • So what do we gotta do to do that?

  • It has to be in the center of this element.

  • Let's start by centering the tool tip itself because it's obviously in the wrong spot needs be centered and then above the element.

  • So let's go ahead and do that.

  • Let's go back to the tool tip top before and what we're gonna do is we're going to position it now and we're gonna say bottom.

  • Um, now, if I just said bottom 100% what's gonna happen, it's gonna move it up.

  • But I want to add another five pixels to that.

  • So because the the the heart, the size of that era was five pixels because we said in our border five pixels.

  • So we want it to be 100% from the bottom, but then another five pixels.

  • Now we can't find out that we can't create that with a percentage.

  • But I also want to have a dynamic tool tip position from the bottom because that element could be any size.

  • If I want to add a tilted to any element, not just a specific, hard coded height, so it needs to be 100% from the bottom, but it needs to have an additional five pixels, and the way we can combine a percentage and pixel value is through the couch CSS function.

  • So check this out.

  • Let's go back to our CSS.

  • I'm gonna wrap this in the Cal HQ function like this, but I'm gonna say, plus five pixels that allows us to combine different values.

  • Different measurements.

  • Now, watch this.

  • 100% plus five pixels.

  • That's amazing.

  • How cool is that?

  • So now we need to fix that, Uh, needs to move it over.

  • So let me let me do another thing here.

  • We're going to Ah, we gotta move it left.

  • Let's say left.

  • 50%.

  • Save that.

  • See what happens.

  • Okay, so now we're 50% over Now.

  • We're starting to look good.

  • 50% over from the left side of the parent element, as you could see as well as the little Aero is, it's in the bottom left hand corner of the tool tip.

  • But we need to fix that.

  • We need to move it back over.

  • So how we do that is through a We could just simply say margin left, you know, uh, you know, negative, whatever the width is of the element, but I want to use trans form.

  • The reason why is because this is kind of an animated elements.

  • It's kind of appearing you know, through a fade.

  • And I just want to want to use this as an example.

  • I could just use the margin, laughed or positioning.

  • But here's the deal.

  • There I found a really cool article about the transform.

  • Specifically, What I'm gonna do is this and I'll tell you exactly why.

  • So translate x So translate the value for the transformed property on the X axes, which means horizontally.

  • So I am to say, negative 50%?

  • No, let me show you what it happens and then we're gonna go from there.

  • So now we're perfectly in the center.

  • So I moved it negative 50% of its width over so that it is perfectly in the center.

  • The reason why I used transformed translators because this article eyes a great article.

  • I have a link in the final code And it this line 58 of the final CSS.

  • With the link to this article, it's basically I wanted to know OK, why would you want to use translate versus an absolute position or, you know, using a margin where you can, you know, negative the amount So it's centered, which we've done before.

  • Well, he basically says, Don't confuse positioning with designing motion.

  • So here's an example.

  • When you use an element that has an absolute position or a margin, you know, negative pixel position, it's going the browsers gonna render that animation if you're moving it at all, pixel by pixel.

  • So this is cool.

  • So in the animation, if you review the source code and you animated it into that position, it's gonna go pixel to know two pixels through pixel for pixels until it goes from whatever, whatever starting pixel to the end, pixel pixel by pixel.

  • So, technically, that's pretty choppy, especially if you had a really good retina screen where you can see the little fine details.

  • But that's not the best practice.

  • How do you do it?

  • So that's more smooth.

  • So it's a renders a bit more smooth.

  • Will you use translates?

  • Ah, transform translate where the browser does something like this.

  • It renders that animation way smoother so it goes in increments so you could see goes from the starting of zero, Let's say, and the final, the final pixels thatyou end on his one pixel.

  • It doesn't just go 01 It goes 0.1 point 2.3 point 4.5 all the way up to your final position so that it's a really smooth animation.

  • So the way Arthur, I believe, is the author here, he says.

  • Don't confuse positioning.

  • So I'm moving an element in a specific and static and hard coded place with design emotion.

  • So possibly I'm thinking here, maybe our Pac Man, instead of using, you know, the moving the pixels across the screen.

  • Maybe I would have used transformed Translate X to move him across the screen.

  • That might be something that you might want to revisit to see if we can improve that instead of using absolute positioning using transform translate.

  • So my little rant on why you would use transform translate.

  • I'm simp simply positioning it in an area.

  • But because it could be fading in and because you could have it slide up or slide down into position, using the transfer of property is a nicer way of handling its position because it's a bit more dynamic.

  • Hopefully, that makes sense, and I didn't go off on a tangent for no reason whatsoever.

  • Okay, so now we've got our tool tip in the right position we want that little arrow to be in the right position.

  • So let's find the tool tip after.

  • Ah, and just for consistency, I'm gonna move this hover above these styles like so And then down here, we're going to start styling the after.

  • So what happens?

  • Let me see.

  • I'm gonna move down a couple and we said bottom 100% and left 50%.

  • So that's good.

  • But what we actually need to do now is, if you can see it needs to be centered properly.

  • It's not actually in the center of the tool tip.

  • So let's try that transform, translate ex again and then say negative 50% and I'll see what it does to it.

  • So now it is actually perfectly centered.

  • This is the scene with on the left as it is on the right, Perfect.

  • But it's not below the tool tip.

  • We wanna be able to see that.

  • That's because let's see if I can do this.

  • This is the top border of an element of ah, five pixel border.

  • And so there are three other sides that you can't see, so we just need to make the border bottom with zero.

  • So that should jump that whole element down.

  • So let's try that.

  • So we're gonna say border bottom with zero now it could have just used position bottom, 100% talc and then extra five pixels.

  • But I just want to make it easy instead of doing anything else and just a border bottom with zero.

  • So now the border top with this five pixels, the border bottom with is nothing, so that should collapse it down below the tool tip.

  • Let's see, just like I said, it would do so.

  • That now means the border.

  • Bottom of that element is zero.

  • You can't.

  • It's nothing there taking up space, and it jumps that arrow down so that it's just touching the tilt upon the top.

  • So there is our top tool tip.

  • That's it for that that style right there.

  • So now all of them have these styles, so that's a little bit of a problem, because they need to be a bit more specific, So the styles are just styled were for all the tool tips.

  • So maybe we'll go back into our CSS here, and what we're going to do is re visit here so the tool tip hover.

  • It's going to display all the tool tips on hover.

  • We want that.

  • But now what we want for for the tool tip top.

  • So we want all the tool tips to have these styles but this stylist specific to the tool tip talk.

  • So I'm gonna cut that out, and what I'm gonna do is this.

  • So I'm gonna actually go down to the bottom and I'm gonna say tool tip, And then I'm gonna combine that with the class of top and then the after pseudo element I believe it was before actually was wth e style we're going for Yes.

  • So that is the tilt of itself.

  • The position of the top tool tip Save that.

  • Okay, Perfect.

  • So now these ones are broken because I'm not selecting them anymore.

  • That is more what we wanted.

  • But we also did the after the position of that arrow is wrong.

  • So we need to specifically take yes.

  • So we're gonna take all these styles because that's specific to where it's gonna be positioned.

  • So now this is just styling, all that all of those elements, as as in terms of its look and feel but the position of it.

  • We want to be very specific.

  • So now down here, I'm gonna say tool tip top.

  • And then the after pseudo element, I add these style.

  • So now let's try that.

  • Told the top works.

  • Great, these ones broken.

  • Beautiful.

  • Okay, so quick Review.

  • We have the tool tip global style.

  • Just for that pink elements we have the When you hover the before and after elements will appear, um, we'll get a display of inline block, the default tool tip before styles.

  • In fact, when we just move these up, reorganizing my code a little bit here, So tool tip and then to a pit till tip after and tilt it before.

  • Okay, so we got those three things and then we have tool tip hover before and after.

  • Then we have tool tip top before that's position to get that in the top center position above the pink element and then told to top after, which is a little arrow in the bottom in the center.

  • That is good.

  • So moving on that was the was the bulk of the work.

  • I think because now what we're gonna be doing, it's just positioning the We already styled up the tool tip.

  • Now we just need to position them.

  • So that helps.

  • So that the tool tip is on the other right bottom or left him the arrows.

  • Aaron, the their respective positions.

  • So rolling up our sleeves here, we're gonna get started.

  • Let's go down here below tool tip top after give a little bit of space.

  • And now what we're gonna do is we're gonna be styling the tool tip.

  • Let's do the one on the right.

  • That's the next one tool tip.

  • Right.

  • So those are connected.

  • That's ah, very specific selector.

  • I'm selecting the class, a tool tip that also has the class of right.

  • And before pseudo element now we're gonna do is going to say top 50% because it needs to be in the center of the elements.

  • So if we look over here, we need that to be centered in vertically.

  • Let's go back here and we're gonna say left.

  • Here's what we're gonna do is we're gonna say left.

  • We're gonna go Cal HQ again.

  • The cal function 100% from the left.

  • Now let's see what's going on here.

  • If I save that check it out.

  • It's going to be all the way over there.

  • Ah, the problem here is a couple things.

  • It's, um we need to have some space for the arrow on that in between the two elements.

  • So we're gonna do the Calcutta 100% plus five pixels that will give us that space.

  • Perfect.

  • And the other problem is the the vertical on the Y axes.

  • That tool tip on the right is just centered from the top.

  • We need to be centered from the middle of the element that makes sense.

  • So we're also going to go transform, translate.

  • Why?

  • So it's on the Y axes Negative.

  • 50%.

  • Save that.

  • Check it out.

  • So now we're in the right spot Now we need to get that arrow on.

  • We need to make that appear properly.

  • So now we're gonna style tool tip with the class of right and the after pseudo element, we're going to say border right color whips is RGB, eh?

  • I don't want to type all this out.

  • I'm gonna copy that.

  • Sergeant B, A 0.8 and then the border, we're gonna say top 50%.

  • So We wanted to be down 30% and then left 100%.

  • So let's let's see what that does.

  • Okay, so from the left, it's 100% because the parent element is here.

  • So left 100%.

  • I believe that's the case.

  • Yep.

  • Well, let's see if it is left.

  • Zero.

  • We'll see what happens.

  • Yes.

  • So see how it's over here.

  • Now what?

  • The other thing is DC How there's a little bit of space.

  • How it's not actually connected to the left side.

  • The element.

  • That's because the other three sides of the border one, two and three are invisible.

  • They're transparent, but they're the width is still there.

  • So want the left width of the border to be zero.

  • So let's do that right now.

  • We're gonna say border left witch zero.

  • Now check it out.

  • Now.

  • We're right at this.

  • The left side.

  • Now we need to position that to be left 100% like were originally doing.

  • But the problem here is it's not actually aligned in the center of that tool tip, and we're going to fix that with the transform property transform immigrants A.

  • Translate why?

  • And you guessed it negative 50%.

  • And that is going to do the trick.

  • I believe there it is.

  • So the tool tip on the right is done.

  • So now we should be able to zip through.

  • That was only about three minutes to code that up.

  • Now our bottom and left should be super easy.

  • So let's jump down to our bottoms or now a little bit of space.

  • I'm just gonna space these out a little bit, so it's easier to find them good organization.

  • So now we're gonna solve that.

  • Bottoms were gonna go Tool tip that also has the class of bottom and the before Pseudo element the top.

  • We're going to need to, Let's see, looking here.

  • So when the bottom it needs to be 100% down from the top, so top will be Cal.

  • We're going to Calcutta again.

  • 100% plus the five pixels for that little arrow.

  • Now we're gonna do is gonna go left.

  • 50% want t o to be centered.

  • But that's gonna create a problem again.

  • Check it out.

  • It's gonna be left from the left side.

  • We need t take off half of the width.

  • So its center.

  • So we're gonna use that transform, and we're gonna use translate on the X axes, translate X.

  • And then that's gonna be negative.

  • 50% say that.

  • That should get us in the center looking very nice.

  • Now, we just need to position that after pseudo element tool tip bottom after.

  • Okay, top 100% left.

  • 50%.

  • We're gonna go border bottom color because you wanted to appear now RGB a 0.8.

  • Save that and see what we got so I can see it there.

  • It's right there, but it's not centered in the middle of the tool tip.

  • And it needs to be up five pixels, So maybe you guessed it.

  • Border top wit zero and transform translate X negative.

  • 50%.

  • Say that.

  • Refresh tulip on the bottom.

  • That's looking nice.

  • And last but not least, tool tip on the left.

  • So we're gonna give a little bit of space in between here.

  • We're gonna say tool tip Also with the class of left and the before, pseudo element is kind of like repetition.

  • Now, at this point, you might be able to do this by yourself.

  • I challenge you, in fact, a posit video.

  • What?

  • Keep me in this frame right here.

  • That one, and code this one up yourself and then hit play.

  • See if you got it.

  • Right.

  • So here we are.

  • You've pause the video and you've coated it up, and you're going to see if you got this right.

  • Now, keep in mind there's multiple ways of doing getting through the same end result.

  • But here's how I'm gonna coat it up.

  • Let's see how close you were gonna say top 50% rights and needs to be 100%.

  • But I need to calculate that with a pixel wit.

  • So 100% from the right plus five pixels to account for that little arrow transform were in a trance.

  • Translate that on the Y axes and we're gonna go negative.

  • 50%.

  • Let's check it out.

  • That's looking nice.

  • And now here we go.

  • We're just gonna simply say tool tip with the class of left and after we're gonna say top 50% left note That's not right.

  • Right?

  • 100%.

  • We're gonna go border left color cause we want the left arrow to appear, and we're gonna say border right, which zero?

  • So where there's no conflict with size, they're transform Translates on the why axes seeming negative 50% to save that boom.

  • I think we just nailed it.

  • So if that's what you're code looks like, or something like that good job.

  • You've got the hang of it.

  • Not set for tool tips.

  • We got to tip on the top right bottom and left purely CSS three.

  • That's awesome.

  • It's really light weight when you do that in CSS three, we did a couple of new things.

  • We played around with a transformed property, which we learned a little bit about why you might want to do that's particularly with animations.

  • A little challenge for you here if you want, because right now these tulips air just up, hearing on Hover.

  • Now we've played around with some animations thus far in this CSS three and 30 days, and we you should know.

  • Or maybe you should be able to figure out how to when you hover, make the tool tips fade in, Or maybe you know, slide in, slide down or slide over, play around with it and see what you come up with.

  • I challenge you to make these tool tips a little bit more animated.

  • And keep in mind the transform and translate style that we learned about positioning and moving things.

  • Using that where it incrementally moves into the position rather than uses Ah, hard coded position at absolutely positioned property where it's only clunking over pixel by pixel.

  • Keep that in mind, but a simple challenge for you is to make these tool tips fade in on hover and play with it from there.

  • I hope you enjoyed today's lesson.

  • Hope it gave you a few ideas for your own websites, applications and all of that.

  • Have a good day.

  • I'll see you tomorrow and day number 19 the NuWave ay dios.

Hello, everybody.

Subtitles and vocabulary

Click the word to look it up Click the word to find further inforamtion about it