Home Web Front-end CSS Tutorial Use css to implement fully compatible tooltip prompt box

Use css to implement fully compatible tooltip prompt box

Dec 20, 2016 pm 02:55 PM

Final rendering:

Use css to implement fully compatible tooltip prompt box

Basic principle

First set an ordinary div box with a background color, and then use the triangle icon obtained in the previous post to set the div box to relative positioning mode, triangle icon Set to absolute positioning, position relative to the div box, and adjust to the appropriate position. This will get a basic tooltip, but it always looks uncomfortable without a border. We can set a border for the div box, which is not difficult, but how to set the border for the triangle icon? Here we use a clever way to superimpose two triangle icons of different colors and stagger their positions by 1px. In this way, the top border of the bottom triangle is covered and only the left and right border parts are exposed. When superimposed together, we get a triangle that looks like a border. icon.

step by step

1. First define a relatively positioned box div:

<div class="tooltips">
  </div>
Copy after login

css:

.tooltips{
position:relative;
width:300px;
height:80px;
line-height:60px;
background:#D7E7FC;
border-radius:4px;
}
Copy after login

Effect:

2. Next, we use the knowledge from the previous post Add a triangle icon to the div box:

<div class="tooltips">
  <div class="arrow "></div>
</div>
Copy after login

Triangle icon css:

.arrow{
  position:absolute;
  color: #D7E7FC;
  width: 0px;
  height:0px;
  line-height: 0px;
  border-width: 20px 15px 0;
  border-style: solid dashed dashed dashed;
  border-left-color: transparent;
  border-right-color: transparent;
  bottom: -20px;
  right: 50%;
}
Copy after login

Effect:

Use css to implement fully compatible tooltip prompt box

It’s starting to take shape, and it can even be used directly, but if the tooltip background If the color coincides with the target background color, it will be difficult for us to distinguish it, so we need to define a border for it.

3. Add border
css:

.tooltips{
  position:relative;
  width:300px;
  height:80px;
  line-height:60px;
  background:#D7E7FC;
  border:1px solid #A5C4EC;
  border-radius:4px;
}
Copy after login

Effect:

Use css to implement fully compatible tooltip prompt box

The box has a border effect, but the small triangle below has not been "protected", which is simply a problem for Virgos Intolerable!

4. Put an elastic band on the "little triangle"
We have already said when explaining the principle that we need to use the method of superimposing two triangles. First, we define two triangle divs, one with the same background color as the border color of the box , a background color consistent with the background color of the box:

<div class="tooltips">
  <div class="arrow arrow-border"></div>
  <div class="arrow arrow-bg"></div>
</div>
Copy after login

css is defined as follows:

.arrow{
  position:absolute;
  width: 0px;
  height:0px;
  line-height: 0px;
  border-width: 20px 15px 0;
  border-style: solid dashed dashed dashed;
  border-left-color: transparent;
  border-right-color: transparent;
}
.arrow-border{
  color: #A5C4EC;
  bottom: -20px;
  right: 50%;
}
.arrow-bg{
  color: #D7E7FC;
  bottom: -19px;
  right: 50%;
}
Copy after login

Note: The difference in the bottom positions of .arrow-bg and .arrow-border is 1px (can be determined according to the border Width adjustment) The order of the two divs cannot be reversed.
Let’s take a look at the final effect:

Use css to implement fully compatible tooltip prompt box

ok! It’s done, run it under IE6, it’s fully compatible!


For more related articles on using css to achieve fully compatible tooltip prompt boxes, please pay attention to the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1662
14
PHP Tutorial
1262
29
C# Tutorial
1236
24
Google Fonts   Variable Fonts Google Fonts Variable Fonts Apr 09, 2025 am 10:42 AM

I see Google Fonts rolled out a new design (Tweet). Compared to the last big redesign, this feels much more iterative. I can barely tell the difference

How to Create an Animated Countdown Timer With HTML, CSS and JavaScript How to Create an Animated Countdown Timer With HTML, CSS and JavaScript Apr 11, 2025 am 11:29 AM

Have you ever needed a countdown timer on a project? For something like that, it might be natural to reach for a plugin, but it’s actually a lot more

HTML Data Attributes Guide HTML Data Attributes Guide Apr 11, 2025 am 11:50 AM

Everything you ever wanted to know about data attributes in HTML, CSS, and JavaScript.

How We Created a Static Site That Generates Tartan Patterns in SVG How We Created a Static Site That Generates Tartan Patterns in SVG Apr 09, 2025 am 11:29 AM

Tartan is a patterned cloth that’s typically associated with Scotland, particularly their fashionable kilts. On tartanify.com, we gathered over 5,000 tartan

A Proof of Concept for Making Sass Faster A Proof of Concept for Making Sass Faster Apr 16, 2025 am 10:38 AM

At the start of a new project, Sass compilation happens in the blink of an eye. This feels great, especially when it’s paired with Browsersync, which reloads

How to Build Vue Components in a WordPress Theme How to Build Vue Components in a WordPress Theme Apr 11, 2025 am 11:03 AM

The inline-template directive allows us to build rich Vue components as a progressive enhancement over existing WordPress markup.

PHP is A-OK for Templating PHP is A-OK for Templating Apr 11, 2025 am 11:04 AM

PHP templating often gets a bad rap for facilitating subpar code — but that doesn&#039;t have to be the case. Let’s look at how PHP projects can enforce a basic

Programming Sass to Create Accessible Color Combinations Programming Sass to Create Accessible Color Combinations Apr 09, 2025 am 11:30 AM

We are always looking to make the web more accessible. Color contrast is just math, so Sass can help cover edge cases that designers might have missed.

See all articles