blob: c8c74f1fa4486a2b5dddb51819c706992e3be842 [file] [log] [blame]
Copybara botbe50d492023-11-30 00:16:42 +01001
2
3
4<h2 id="introduction">Introduction</h2>
5<p>The Material Design Lite (MDL) <strong>tooltip</strong> component is an enhanced version of the standard HTML tooltip as produced by the <code>title</code> attribute. A tooltip consists of text and/or an image that clearly communicates additional information about an element when the user hovers over or, in a touch-based UI, touches the element. The MDL tooltip component is pre-styled (colors, fonts, and other settings are contained in <em>material.min.css</em>) to provide a vivid, attractive visual element that displays related but typically non-essential content, e.g., a definition, clarification, or brief instruction.</p>
6<p>Tooltips are a ubiquitous feature of most user interfaces, regardless of a site&#39;s content or function. Their design and use is an important factor in the overall user experience. See the tooltip component&#39;s <a href="http://www.google.com/design/spec/components/tooltips.html">Material Design specifications page</a> for details.</p>
7<h3 id="to-include-an-mdl-tooltip-component-">To include an MDL <strong>tooltip</strong> component:</h3>
8<p>&nbsp;1. Code an element, such as a <code>&lt;div&gt;</code>, <code>&lt;p&gt;</code>, or <code>&lt;span&gt;</code>, and style it as desired; this will be the tooltip&#39;s target. Include an <code>id</code> attribute and unique value to link the container to its tooltip.</p>
9<pre><code class="lang-html">&lt;p id=&quot;tt1&quot;&gt;HTML&lt;/p&gt;
10</code></pre>
11<p>&nbsp;2. Following the target element, code a second element, such as a <code>&lt;div&gt;</code>, <code>&lt;p&gt;</code>, or <code>&lt;span&gt;</code>; this will be the tooltip itself. Include a <code>for</code> (or <code>data-mdl-for</code>) attribute whose value matches that of the target&#39;s <code>id</code>.</p>
12<pre><code class="lang-html">&lt;p id=&quot;tt1&quot;&gt;HTML&lt;/p&gt;
13&lt;span for=&quot;tt1&quot;&gt;HyperText Markup Language&lt;/span&gt;
14</code></pre>
15<p>&nbsp;3. Add one or more MDL classes, separated by spaces, to the tooltip element using the <code>class</code> attribute.</p>
16<pre><code class="lang-html">&lt;p id=&quot;tt1&quot;&gt;HTML&lt;/p&gt;
17&lt;span for=&quot;tt1&quot; class=&quot;mdl-tooltip&quot;&gt;HyperText Markup Language&lt;/span&gt;
18</code></pre>
19<p>The tooltip component is ready for use.</p>
20<h4 id="examples">Examples</h4>
21<p>A target with a simple text tooltip.</p>
22<pre><code class="lang-html">&lt;p&gt;HTML is related to but different from &lt;span id=&quot;xml&quot;&gt;&lt;i&gt;XML&lt;/i&gt;&lt;/span&gt;.&lt;/p&gt;
23&lt;span class=&quot;mdl-tooltip&quot; for=&quot;xml&quot;&gt;eXtensible Markup Language&lt;/span&gt;
24</code></pre>
25<p>A target with &quot;rich&quot; (containing HTML markup) tooltip text.</p>
26<pre><code class="lang-html">&lt;p&gt;HTML is related to but different from &lt;span id=&quot;xml&quot;&gt;&lt;i&gt;XML&lt;/i&gt;&lt;/span&gt;.&lt;/p&gt;
27&lt;span class=&quot;mdl-tooltip&quot; for=&quot;xml&quot;&gt;e&lt;b&gt;X&lt;/b&gt;tensible &lt;b&gt;M&lt;/b&gt;arkup &lt;b&gt;L&lt;/b&gt;anguage&lt;/span&gt;
28</code></pre>
29<p>A target with a long text tooltip that automatically wraps.</p>
30<pre><code class="lang-html">&lt;p&gt;HTML is related to but different from &lt;span id=&quot;xml&quot;&gt;&lt;i&gt;XML&lt;/i&gt;&lt;/span&gt;.&lt;/p&gt;
31&lt;span class=&quot;mdl-tooltip&quot; for=&quot;xml&quot;&gt;XML is an acronym for eXtensible Markup Language&lt;/span&gt;
32</code></pre>
33<p>A target with tooltip text in a larger font size.</p>
34<pre><code class="lang-html">&lt;p&gt;HTML is related to but different from &lt;span id=&quot;xml&quot;&gt;&lt;i&gt;XML&lt;/i&gt;&lt;/span&gt;.&lt;/p&gt;
35&lt;span class=&quot;mdl-tooltip mdl-tooltip--large&quot; for=&quot;xml&quot;&gt;eXtensible Markup Language&lt;/span&gt;
36</code></pre>
37<p>A target with a tooltip containing both an image and text.</p>
38<pre><code class="lang-html">&lt;p&gt;HTML is related to but different from &lt;span id=&quot;xml&quot;&gt;&lt;i&gt;XML&lt;/i&gt;&lt;/span&gt;.&lt;/p&gt;
39&lt;span class=&quot;mdl-tooltip&quot; for=&quot;xml&quot;&gt;
40&lt;img src=&quot;xml-logo-small.png&quot; width=&quot;20&quot; height=&quot;10&quot;&gt; eXtensible Markup Language&lt;/span&gt;
41</code></pre>
42<h2 id="configuration-options">Configuration options</h2>
43<p>The MDL CSS classes apply various predefined visual enhancements to the tooltip. The table below lists the available classes and their effects.</p>
44<table>
45<thead>
46<tr>
47<th>MDL class</th>
48<th>Effect</th>
49<th>Remarks</th>
50</tr>
51</thead>
52<tbody>
53<tr>
54<td><code>mdl-tooltip</code></td>
55<td>Defines a container as an MDL tooltip</td>
56<td>Required on tooltip container element</td>
57</tr>
58<tr>
59<td><code>mdl-tooltip--large</code></td>
60<td>Applies large-font effect</td>
61<td>Optional; goes on tooltip container element</td>
62</tr>
63<tr>
64<td><code>mdl-tooltip--left</code></td>
65<td>Positions the tooltip to the left of the target</td>
66<td>Optional; goes on tooltip container element</td>
67</tr>
68<tr>
69<td><code>mdl-tooltip--right</code></td>
70<td>Positions the tooltip to the right of the target</td>
71<td>Optional; goes on tooltip container element</td>
72</tr>
73<tr>
74<td><code>mdl-tooltip--top</code></td>
75<td>Positions the tooltip to the top of the target</td>
76<td>Optional; goes on tooltip container element</td>
77</tr>
78<tr>
79<td><code>mdl-tooltip--bottom</code></td>
80<td>Positions the tooltip to the bottom of the target</td>
81<td>Optional; goes on tooltip container element</td>
82</tr>
83</tbody>
84</table>
85
86