Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member

Styling the tooltip

From: Create a Tooltip with jQuery

Video: Styling the tooltip

Now to create a CSS rule to style our tip container, we're going to need to open the tooltip.css file. So from your text editor, choose File > Open, from the myTooltip folder let's go into includes and let's open tooltip.css. Now there are CSS rules in here which are controlling our layout and style, and down at the very bottom we have a comment for Tooltip. This is where we're going to add our own custom rules for the tooltip. So I'll just add a few lines here at the bottom and what we are going to want to do is target that tooltip_container.

Styling the tooltip

Now to create a CSS rule to style our tip container, we're going to need to open the tooltip.css file. So from your text editor, choose File > Open, from the myTooltip folder let's go into includes and let's open tooltip.css. Now there are CSS rules in here which are controlling our layout and style, and down at the very bottom we have a comment for Tooltip. This is where we're going to add our own custom rules for the tooltip. So I'll just add a few lines here at the bottom and what we are going to want to do is target that tooltip_container.

Now it is an id, so we target that with the pound sign, tooltip_container, then beginning and ending bracket. Let's split these brackets open. Now the first property we're going to set is going to be the color of the type, so we're going to set color: # fff; for white Next line, we're going to set position of absolute, this way the tooltip with absolute positioning can hover over the top of other objects and have its position changed without any relation to the other divs on the page.

Next line, we're going to set padding of 20 pixels, that's going to set padding on the top right bottom and left. We're going to set a max-width of 200px, that way regardless of any content we put inside out there, the tooltip will never get wider than 200. And of course, you can customize this for other values. Next, we're going to set the background-color. Now we're going to use the RGBA color space. So we're going to type after background-color: rgba, beginning and ending parenthesis, then a semicolon.

Inside of the parenthesis we're to specify the red, then the green, then the blue and then the alpha. So to get black with RGBA, we need to set the RGB values all to 0. So I will type a 0 for red, 0 for green, 0 for blue, then .85. This is going to give us 85% Opacity. Next we want to specify rounded corners, and we still need to use some specific rendering engine flags. The first is going to be webkit.

This is going to target Chrome, Safari, Android and the iOS Platform. So -webkit-border-radius, colon, space. We are going to set this to 12px. Next, we're going to set the flag for the rendering engine that runs inside of Firefox, which is Mozilla. So I'm going to copy that entire line and then replace webkit with moz for Mozilla.

Then on the next line we're going to add the straight CSS3 property, which actually is supported in IE 9, and other browsers are starting to support the straight CSS property instead of using rendering engine flags. So we'll type border-radius: 12px. Once these properties are added, let's choose File > Save, and now let's open up the Internet Explorer version of the CSS file. So in the code editor, let's choose File > Open. Let's open tooltip_ie.css.

So inside of here we're going to target to tooltip_containers as well, #tooltip_container, beginning and ending bracket, split that open. Now IE 7 and 8 don't support the maximum width setting, so we're going to come in here and simply set a width of 200px. On the next line we're going to set background, colon, space, then we are going to type none with a semicolon.

So here we want to clear out all of the background settings, since IE 7 and 8 don't understand the RGBA setting for background-color. So we'll just set background to none. Then on this line, we're going to specify a background image and use that transparent PNG, so we're going to type background-image: url(../images/ie_transparency.png);.

So again, we're setting the width, because IE 7 and 8 don't understand max-width. We're clearing out the background to get rid of the background color we specified in the tooltip.css, and then the background image we're bringing in with the semi-transparent PNG. That's going to gives us the same effect as the CSS3 is giving us in the other browsers. Now again, if we go back to the index.html file and then scroll to the top, remember we're only bringing in this CSS rule for IE 7 and 8. So other browsers are going to completely ignore everything on line 9 through 12.

They are going ignore the Google Shiv, they are going to ignore the tooltip.css; only IE 7 and 8 are going to see this. So now with our CSS rules in place, let's come back to our project folder, let's open up the HTML file up in a browser, let's hit Reload, and we should see the This is my tooltip in the lower left-hand corner here. We see our rounded corners. We see that the background is 85% opaque against the blue background, and we see that the container is actually showing up after the footer element. Now even though we did specify absolute positioning on this object, we haven't given it a top or a left property yet.

So we haven't actually told it to position itself anywhere. We're going to be doing that later on with JavaScript.

Show transcript

This video is part of

Image for Create a Tooltip with jQuery
Create a Tooltip with jQuery

18 video lessons · 5180 viewers

Chris Converse
Author

 

Start learning today

Get unlimited access to all courses for just $25/month.

Become a member
Sometimes @lynda teaches me how to use a program and sometimes Lynda.com changes my life forever. @JosefShutter
@lynda lynda.com is an absolute life saver when it comes to learning todays software. Definitely recommend it! #higherlearning @Michael_Caraway
@lynda The best thing online! Your database of courses is great! To the mark and very helpful. Thanks! @ru22more
Got to create something yesterday I never thought I could do. #thanks @lynda @Ngventurella
I really do love @lynda as a learning platform. Never stop learning and developing, it’s probably our greatest gift as a species! @soundslikedavid
@lynda just subscribed to lynda.com all I can say its brilliant join now trust me @ButchSamurai
@lynda is an awesome resource. The membership is priceless if you take advantage of it. @diabetic_techie
One of the best decision I made this year. Buy a 1yr subscription to @lynda @cybercaptive
guys lynda.com (@lynda) is the best. So far I’ve learned Java, principles of OO programming, and now learning about MS project @lucasmitchell
Signed back up to @lynda dot com. I’ve missed it!! Proper geeking out right now! #timetolearn #geek @JayGodbold
Share a link to this course

What are exercise files?

Exercise files are the same files the author uses in the course. Save time by downloading the author's files instead of setting up your own files, and learn by following along with the instructor.

Can I take this course without the exercise files?

Yes! If you decide you would like the exercise files later, you can upgrade to a premium account any time.

Become a member Download sample files See plans and pricing

Please wait... please wait ...
Upgrade to get access to exercise files.

Exercise files video

How to use exercise files.

Learn by watching, listening, and doing, Exercise files are the same files the author uses in the course, so you can download them and follow along Premium memberships include access to all exercise files in the library.


Exercise files

Exercise files video

How to use exercise files.

For additional information on downloading and using exercise files, watch our instructional video or read the instructions in the FAQ.

This course includes free exercise files, so you can practice while you watch the course. To access all the exercise files in our library, become a Premium Member.

Are you sure you want to mark all the videos in this course as unwatched?

This will not affect your course history, your reports, or your certificates of completion for this course.


Mark all as unwatched Cancel

Congratulations

You have completed Create a Tooltip with jQuery.

Return to your organization's learning portal to continue training, or close this page.


OK
Become a member to add this course to a playlist

Join today and get unlimited access to the entire library of video courses—and create as many playlists as you like.

Get started

Already a member?

Become a member to like this course.

Join today and get unlimited access to the entire library of video courses.

Get started

Already a member?

Exercise files

Learn by watching, listening, and doing! Exercise files are the same files the author uses in the course, so you can download them and follow along. Exercise files are available with all Premium memberships. Learn more

Get started

Already a Premium member?

Exercise files video

How to use exercise files.

Ask a question

Thanks for contacting us.
You’ll hear from our Customer Service team within 24 hours.

Please enter the text shown below:

The classic layout automatically defaults to the latest Flash Player.

To choose a different player, hold the cursor over your name at the top right of any lynda.com page and choose Site preferencesfrom the dropdown menu.

Continue to classic layout Stay on new layout
Exercise files

Access exercise files from a button right under the course name.

Mark videos as unwatched

Remove icons showing you already watched videos if you want to start over.

Control your viewing experience

Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.

Interactive transcripts

Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.

Are you sure you want to delete this note?

No

Your file was successfully uploaded.

Thanks for signing up.

We’ll send you a confirmation email shortly.


Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

Keep up with news, tips, and latest courses with emails from lynda.com.

Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

   
submit Lightbox submit clicked
Terms and conditions of use

We've updated our terms and conditions (now called terms of service).Go
Review and accept our updated terms of service.