11

How to Create a Tooltip Using CSS?

 2 years ago
source link: https://uxplanet.org/how-to-create-a-tooltip-using-css-a1c0622f77d4
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

How to Create a Tooltip Using CSS?

And why should you use them?

Tooltips are especially useful for highlighting changes that are easy to miss, delivering value quickly, and then stepping aside. Part of what makes Tooltips so useful is that they are contextual and specific — they appear in the product itself and are linked to individual features, allowing you to educate users throughout the process of discovering features.

Benefits of tooltips:

  1. Make your site more readable. As always, the less text you put on your site’s main interface, the better. If you can hide a clue that visitors don’t want or need, you can keep your site clean and free of potentially intrusive text.
  2. Provide additional information to visitors who want it. Let’s say you have a blog site that only shows an image and the title of the article on the home page. Instead of forcing visitors to click to start reading, you can use contextual hints to provide additional descriptive information so they can decide if they really want to take that action.
  3. Reduce unnecessary steps. Although the design of your site should already be intuitive, there are some points that can trip visitors. Rather than leaving them frustrated, confused, or needing to contact you for clarification, the suggestions can be a guide built into your website.
  4. Improve accessibility. Accessibility should always play a role in the planning and implementation stages when developing your website. Therefore, the tips can be very helpful in providing additional guidance to visitors with disabilities.
  5. Guide your visitors to take action. If you’ve ever felt the need to have more control over how to get visitors to take action, suggestions can give you an extra layer of advice without having to add another call to action into your design site.

For more in-depth details about Tooltips:

Adding a simple tooltip to your page or app isn’t difficult. You can easily find a plethora of JavaScript plugins and tooltip scripts that will work just fine. But pure CSS is often a better option and has become the preferred choice of many web designers.

Creating a Tooltip:

First, you need to create two Files one HTML File and another one is CSS File. After creating these files just paste the following codes in your file.

1. HTML:

<div class=”section”>
<h3>Tooltip</h3>
<div id=”anim”>
<span class=”tooltip” data-tooltip=”Now, Create your own amazing tooltips”>?</span>
</div>
</div>

2. CSS:

body {
background: #0e0a1b;
font-family: “Open Sans”;
overflow: hidden;
}
.section {
display: flex;
justify-content: center;
align-items: center;
position: relative;
width: 100%;
height: 100vh;
}
h3 {
font-size: 48px;
font-weight: 600;
color: #fff;
padding-left: 10px;
}
.tooltip {
position: relative;
background: #1687d9;
padding: 5px 18px;
margin: 5px;
font-size: 26px;
border-radius: 100%;
color: #FFF;
}.tooltip:before,
.tooltip:after {
position: absolute;
content: ‘’;
opacity: 0;
transition: all 0.4s ease;
}.tooltip:before {
border-width: 10px 8px 0 8px;
border-style: solid;
border-color: #1687d9 transparent transparent transparent;
top: -15px;
transform: translateY(20px);
}.tooltip:after {
content: attr(data-tooltip);
background: #1687d9;
width: 160px;
height: 40px;
font-size: 14px;
font-weight: 400;
top: -75px;
left: -10px;
padding: 10px;
border-radius: 5px;
letter-spacing: 1px;
transform: translateY(20px);
}.tooltip:hover::before,
.tooltip:hover::after {
opacity: 1;
transform: translateY(-2px);
}@keyframes shake {
0% {
transform: rotate(2deg);
}
50% {
transform: rotate(-3deg);
}
70% {
transform: rotate(3deg);
}
100% {
transform: rotate(0deg);
}
}#anim:hover {
animation: shake 500ms ease-in-out forwards;
}

3. Final Preview:

1*_i4YrsG8rB0fxMn7oLpHjQ.gif?q=20
how-to-create-a-tooltip-using-css-a1c0622f77d4
Final Preview

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK