W3.CSS ツールチップ

❮ 前章へ 次章へ ❯

ツールチップとは、HTML 要素の上にカーソルを乗せた時に、テキスト(または他のコンテンツ)を表示するものです。


インライン・ツールチップ・テキスト

下の文章の上にマウスを乗せてください!

London 9 million is the capital city of England.

w3-tooltip クラスは、マウスを上にホバーする HTML 要素を定義します(ツールチップコンテナ)。

w3-text クラスは、ツールチップ・テキストを定義します:

<p class="w3-tooltip">London
<span class="w3-text">9 million</span>
is the capital city of England</p>
Try It Yourself ❯

インライン・ツールチップ・タグ

下の文章の上にマウスを乗せてください!

London 9 million is the capital city of England.

<p class="w3-tooltip">London
<span class="w3-text w3-tag">9 million</span>
is the capital city of England</p>
Try It Yourself ❯

画像ツールチップ

効果を確認するために、この写真の上にマウスを乗せてください:

Car

A car is a wheeled, self-powered motor vehicle used for transportation. Most definitions of the term specify that cars typically have four wheels.(Wikipedia)

w3-tooltip クラスは、マウスを上にホバーする HTML 要素を定義します(ツールチップコンテナ)。

w3-text クラスは、ツールチップ・テキストを定義します:

例 (写真の前にテキストを表示)

<div class="w3-tooltip">
  <p class="w3-text">A car is a...</p>
  <img src="img_car.jpg" alt="Car">
</div>
Try It Yourself ❯

例 (写真の後にテキストを表示)

<div class="w3-tooltip">
  <img src="img_car.jpg" alt="Car">
  <p class="w3-text">A car is a...</p>
</div>
Try It Yourself ❯

絶対配置のツールチップ

ツールチップを絶対位置に表示したい場合は、ツールチップのテキスト (w3-text) を CSS で配置します:

If you want the tooltip to appear in an absolute position, position the tooltip text (w3-text) with CSS:

London 9 million is the capital city of England.

<p class="w3-tooltip">London is the capital city of England.
<span style="position:absolute;left:0;bottom:18px"
class="w3-text w3-tag">9 million</span></p>
Try It Yourself ❯

色付きツールチップ

ツールチップに色を付けたい場合は、w3-color クラスを使用します:

<span class="w3-text w3-tag w3-red">9 million</span>
Try It Yourself ❯

角丸ツールチップ

ツールチップの角を丸めたい場合は、w3-round クラスを使用します:

<span class="w3-text w3-tag w3-round">9 million</span>
Try It Yourself ❯

小さなツールチップ

小さなツールチップにしたい場合は、w3-small クラスを使用します:

<span class="w3-text w3-tag w3-small">9 million</span>
Try It Yourself ❯

極小さなツールチップ

極小さなツールチップにしたい場合は、w3-tiny クラスを使用します:

<span class="w3-text w3-tag w3-tiny">9 million</span>
Try It Yourself ❯

大きなツールチップ

大きなツールチップにしたい場合は、w3-large クラスを使用します:

<span class="w3-text w3-tag w3-xlarge">9 million</span>
Try It Yourself ❯

アニメ付きツールチップ

ツールチップをフェードインしたい場合は、w3-animate-opacity クラスを使用します:

<span class="w3-text w3-tag w3-animate-opacity">9 million</span>
Try It Yourself ❯

❮ 前章へ 次章へ ❯