<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd"
>

<channel>
	<title>John Desu &#187; CSS</title>
	<atom:link href="http://www.johndesu.com/category/css-tutorials/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.johndesu.com</link>
	<description>culture, tech, music, and code</description>
	<lastBuildDate>Sat, 05 Jun 2010 04:52:54 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
<!-- podcast_generator="Blubrry PowerPress/1.0.9" mode="advanced" entry="normal" -->
	<itunes:summary>Monthly or so mixes of the latest electronic, progressive, and trance tunes.</itunes:summary>
	<itunes:author>John Dyer</itunes:author>
	<itunes:explicit>no</itunes:explicit>
	<itunes:image href="http://www.johndesu.com/images/podcastlogo.jpg" />
	<itunes:owner>
		<itunes:name>John Dyer</itunes:name>
		<itunes:email>lbrapid@gmail.com</itunes:email>
	</itunes:owner>
	<managingEditor>lbrapid@gmail.com (John Dyer)</managingEditor>
	<itunes:subtitle>Moving forward with the web and great music</itunes:subtitle>
	<itunes:keywords>trance,free,mixes,electronic,electro,progressive</itunes:keywords>
	<image>
		<title>John Desu &#187; CSS</title>
		<url>http://www.johndesu.com/images/podcastlogo.jpg</url>
		<link>http://www.johndesu.com/category/css-tutorials/</link>
	</image>
	<itunes:category text="Music" />
	<itunes:category text="Technology">
		<itunes:category text="Podcasting" />
	</itunes:category>
		<item>
		<title>Tooltips in CSS</title>
		<link>http://www.johndesu.com/2009/01/14/tooltips-in-css/</link>
		<comments>http://www.johndesu.com/2009/01/14/tooltips-in-css/#comments</comments>
		<pubDate>Wed, 14 Jan 2009 17:08:45 +0000</pubDate>
		<dc:creator>John Dyer</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[tooltips]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[xhtml]]></category>

		<guid isPermaLink="false">http://www.johndesu.com/?p=86</guid>
		<description><![CDATA[A tooltip is a small box that appear near an object in a graphical user interface when a pointer or other cursor controlled by a mouse passes over or rests on that object and which contains a brief text message identifying or explaining the object. In the context of a website the information shown in [...]]]></description>
			<content:encoded><![CDATA[<p>A tooltip is a small box that appear near an object in a graphical user interface when a pointer or other cursor controlled by a mouse passes over or rests on that object and which contains a brief text message identifying or explaining the object. In the context of a website the information shown in a tooltip is read from the title tags of an element on a page. These are stylized all over the web general using JavaScript and CSS. That&#8217;s not what I&#8217;m going to be teaching you to create though. I am going to show you how to write a tooltip in pure CSS.</p>
<p>Let&#8217;s start with a basic XHTML document.</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">p</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://www.johndesu.com/&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;tooltip&quot;</span>&gt;</span>
    John Dyer<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">span</span>&gt;</span> (Visit my blog) <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">span</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;</span>
    is a student at the University of Pittsburgh majoring in computer science.
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">p</span>&gt;</span></pre></div></div>

<p>Notice that the link has been given a class of tooltip. Inside my link I have added the text I want to be displayed as the link text and the text I want to be displayed in a tooltip. It is good practice to enclose the tooltip text in brackets like I have done so that it will still make sense if styles are turned off.</p>
<p>Now we need to set the position property of the anchor tag to relative in order to be able to position the contents of the span absolutely in relation to it&#8217;s parent element, the anchor tag. We also don&#8217;t want the tooltip text to display by default so we will set it&#8217;s display property to none.</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;">a<span style="color: #6666ff;">.tooltip</span> <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">relative</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
a<span style="color: #6666ff;">.tooltip</span> span <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">none</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>Next we want to make the text contained in the span tag appear when the anchor is hovered over. We do this by setting the display property of tooltip:hover span to block and positioning the contents of the span below and to the right of anchor using absolute positioning.</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;">a<span style="color: #6666ff;">.tooltip</span><span style="color: #3333ff;">:hover </span>span <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">block</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">absolute</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">top</span><span style="color: #00AA00;">:</span> <span style="color: #933;">1em</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">:</span> <span style="color: #933;">2em</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>And that&#8217;s really all there is to it. Let&#8217;s add some custom styling now to make it look more like a tooltip. Feel free to change any of stylistic settings to your liking. This is obviously just an example.</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;">a<span style="color: #6666ff;">.tooltip</span><span style="color: #3333ff;">:hover </span>span <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">block</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">absolute</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">top</span><span style="color: #00AA00;">:</span> <span style="color: #933;">1em</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">:</span> <span style="color: #933;">2em</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span> <span style="color: #933;">1px</span> <span style="color: #993333;">solid</span> <span style="color: #cc00cc;">#996633</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span> <span style="color: #933;">0.3em</span> <span style="color: #933;">0.5em</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">background-color</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#FFFF66</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#000</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>Note that this technique requires a standards compliant browser such as Firefox. Of course there are issues in IE and for some reason there can be problems in Safari as well. A quick fix for IE 5.x from <a href="http://www.andybudd.com">Andy Budd</a> is the following:</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;">a<span style="color: #6666ff;">.tooltip</span><span style="color: #3333ff;">:hover </span><span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span> <span style="color: #933;"><span style="color: #cc66cc;">100</span>%</span><span style="color: #00AA00;">;</span> <span style="color: #808080; font-style: italic;">/* Fixes bug in IE5.x/Win */</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p><a href="http://www.johndesu.com/tutorials/css/tooltips/index.html">View a working example</a></p>
<p><em>If you enjoyed this tutorial, why not <a href="http://www.johndesu.com/feed/">subscribe</a> to my feed to receive the latest updates and tutorials from JohnDesu.</em></p>
<img src="http://www.johndesu.com/?ak_action=api_record_view&id=86&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.johndesu.com/2009/01/14/tooltips-in-css/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
