Welcome Guest ( Log In | Register)



 
Reply to this topicStart new topic
> Tool Tips Using Only Css To Pop Up The Tool Tip, No javascript involved!
jlhaslip
post Mar 2 2006, 10:44 PM
Post #1


A computer once beat me at chess, but it was no match for me at kick boxing.
Group Icon

Group: [MODERATOR]
Posts: 3,874
Joined: 24-July 05
From: In Trouble Again... still?
Member No.: 9,787
Spam Patrol



Tool Tip Tutorial

Example Found Here.

Please review before continuing.

Nice. And no javascript at all to be found. The colours I have used are for demonstration purposes only to show you that they are adjustable to suit the background or to contrast against them. Your choice. That is a styling issue. It is your site, you decide.

The original author's idea was to add position:relative to the link, in order to allow the span element inside to position absolutely in respect to the parent link.
This code has been tested in Ie5.5, IE6, Opera7.11 and Mozilla 1.4 and works fine. Fails in IE5/mac and NN7/mac, as I found out the hard way.

Now, let's have a look at the basic html and css code for the tooltip:

An Anchor Tag with a Span for the Tool Tip Text

CODE
<a class=info href="Your Linked URL  goes Here">display text here <span> Tool Tip Text Here </span> </a>


How it Works
The class="info" sets the background colour, the text colour , the position relative and turns off the underlining for the anchors of this class.


The span tag of this anchor is used to hide the display of the spanned text (a.info span{display: none}). When it is hovered over, it resets the background colour of the anchor(a.info:hover), then the span is made visible in an offset position from the anchor (a.info:hover span).

The attributes of the displayed span are set using the a.info:hover span selector.
In this example, it is used to set the text colour and the background colour of the Tool Tip, it locates the displayed text block as an absolutely positioned block from the anchor, adds a border, and alters the text colour.

Sounds like a lot of work for one little selector.

And here is the CSS for the Anchor and Span
CODE
a.info{
    position:relative; /*this is the key*/
    z-index:24; background-color:#f0c0c0;
    color:#666;
    text-decoration:none}

a.info:hover{z-index:25; background-color:#e1e1e1}

a.info span{display: none}

a.info:hover span{ /*the span will display just on :hover state*/
    display:block;
    position:absolute;
    top:2em; left:2em; width:15em;
    border:1px solid #0cf;
    background-color:#cfc;
    color:#cc3366;
    text-align: center}


Enjoy.
Go to the top of the page
 
+Quote Post
wild20
post Mar 3 2006, 12:03 AM
Post #2


Never alone with Christ
*********

Group: Members
Posts: 647
Joined: 22-July 05
Member No.: 9,713



Works fine in 6.0 Jim. Sorry it took so long to find it. Anyway. I like it. I could use it with a change in background colors. It needs to be better though with the text highlight. Is that easily changable? I didn't look the code over a lot. I know very little PHP and even less CSS, but enough to see how it works. And I give it a rating of 4:5. Thre are better ones out there, but it is amazing how you did it with CSS only. Very cool, thanks for sharing.
Go to the top of the page
 
+Quote Post
Lyon2
post Mar 3 2006, 12:06 AM
Post #3


The Ethical Hacker
***********

Group: [HOSTED]
Posts: 1,144
Joined: 27-May 05
From: Portugal (Europe)
Member No.: 7,566



Very interesting!

Very usefull for me. I Used to use javascripts wich has so many code, but now i'll use css, it's much more easy.

Thanks.
Go to the top of the page
 
+Quote Post
Albus Dumbledore
post Mar 3 2006, 12:06 AM
Post #4


Hidden Secrets can't be told threw just words. One must feel what the other feels to truely understand...
**************

Group: Members
Posts: 1,523
Joined: 8-January 06
From: Sacramento California
Member No.: 16,756



@ wild, i dont mean to speak on a question that you asked jlhaslips but i believe that if you change all of the background attributes
QUOTE
a.info{
position:relative; /*this is the key*/
z-index:24; background-color:#f0c0c0;
color:#666;
text-decoration:none}

a.info:hover{z-index:25; background-color:#e1e1e1}

a.info span{display: none}

a.info:hover span{ /*the span will display just on :hover state*/
display:block;
position:absolute;
top:2em; left:2em; width:15em;
border:1px solid #0cf;
background-color:#cfc;
color:#cc3366;
text-align: center}


i believe if you change the background attributes it will work, im going to test that out on my site and edit this if it doesnt work
Go to the top of the page
 
+Quote Post
Tyssen
post Mar 3 2006, 12:06 AM
Post #5



***********

Group: Members
Posts: 1,161
Joined: 9-May 05
From: Brisbane, QLD
Member No.: 6,818



Nice tutorial Jim. If you wanted to get just a little bit fancier, you could add this to a.info hover span:

CODE
opacity:0.95;
filter:alpha(opacity=95);

Of course, it doesn't validate because of the MS filter though and you'd have to have the opacity quite high to make the text readable against the background.
Go to the top of the page
 
+Quote Post
jlhaslip
post Mar 3 2006, 12:54 AM
Post #6


A computer once beat me at chess, but it was no match for me at kick boxing.
Group Icon

Group: [MODERATOR]
Posts: 3,874
Joined: 24-July 05
From: In Trouble Again... still?
Member No.: 9,787
Spam Patrol



Well, thanks for the support.
It is nice to know that these efforts are appreciated

Wild20: Albus has it right on the mark for changing background-colors to affect the displayed and on:hover colours of the background. To alter the colour of the text, change the color: #fxxxxxx where xxxxxx are hex numbers from 0 to f.
( #ffffff being white and #000000 being black).
The pairs indicate the amount of Red, Green, and Blue, so #ff0000 is full red, #00ff00 is full Green and #0000ff is full blue. There are any number of choices available.

Albus: Thanks for the comment. Always appreciate help around here.

Lyons: Enjoy.

Tyssen: thanks for the tip. My old beater doesn't like opacity whether it is proprietary or not. Don't know if it is the Browser or the machine, but others will appreciate the tip.
Go to the top of the page
 
+Quote Post
Albus Dumbledore
post Mar 3 2006, 01:14 AM
Post #7


Hidden Secrets can't be told threw just words. One must feel what the other feels to truely understand...
**************

Group: Members
Posts: 1,523
Joined: 8-January 06
From: Sacramento California
Member No.: 16,756



i asked jlhaslips if i could post this and he said yes, so i am going to :-D

i was bored and did those for a few of the peole who dont quite know what to edit to change what colors etc.. so this is just to SHOW you what is what and what you should change to get what you want..

CODE
a.info{
    position:relative; /*this is the key*/
    z-index:24; background-color:#f0c0c0;   /*changes the highlight color of the text that the info will show up for*/
    color:#666; /*it changes the tint of the text that is highlighted*/
    text-decoration:none}

a.info:hover{z-index:25; background-color:#e1e1e1}  /*changes the background color of the text when you hover over it*/

a.info span{display: none} /*hides the span until on:hover happens*/

a.info:hover span{ /*the span will display just on :hover state*/
    display:block;
    position:absolute;
    top:2em; left:2em; width:15em;
    border:1px solid #0cf; /*obviously the border color of the info box that shows up on hoover*/
    background-color:#cfc; /*changes the background color of the info box that shows up on hover*/
    color:#cc3366; /*changes the tint of the text that shows up on hover*/
    text-align: center} /*alignment of the text that shows up on hoover*/


DO NOT copy and paste that for the CSS the <<TEXT HERE will mess it up..use the origional one that jlhaslips gave you :-D hope this helps some people happy.gif

This post has been edited by Albus Dumbledore: Mar 3 2006, 05:56 AM
Go to the top of the page
 
+Quote Post
Tyssen
post Mar 3 2006, 05:10 AM
Post #8



***********

Group: Members
Posts: 1,161
Joined: 9-May 05
From: Brisbane, QLD
Member No.: 6,818



If you want to insert comments into CSS files in future, do this:
element { style; } /* your comment */
Go to the top of the page
 
+Quote Post
Albus Dumbledore
post Mar 3 2006, 05:50 AM
Post #9


Hidden Secrets can't be told threw just words. One must feel what the other feels to truely understand...
*