Jump to content
ellenjones6

Problems with Tooltips

Recommended Posts

I need help solving two problems I am encountering with some tooltips that I created based on the W3Schools tooltip tutorial.  

Here is the page with the tooltips:  http://wildadirondacks.org/adirondack-wildflowers-starflower-trientalis-borealis.html 

Here is my html code for one of the paragraphs with tooltips: 

    <p>Starflower <strong>leaves</strong> vary considerably in size, from 1½ inches to about 4 inches  in length.</p>
      <ul>
        <li>Starflower leaves  are <div class="tooltip">lance-shaped<span class="tooltiptext"><img src="images/Lanceolate.jpg" alt="Lanceolate" title="Lanceolate">Lanceolate: A leaf shaped like a lance head, tapering to a point at each end.</span></div>
          , tapering to a tip. </li>
        <li>The leaves are arranged in a single <div class="tooltip">whorl
  <span class="tooltiptext"><img src="images/Whorled.jpg" alt="Whorled Leaf Arrangement" title="Whorled Leaf Arrangement">Whorled: Leaves arranged in a circle around a central point.</span>
</div> with 5 to 9 leaves (most commonly 7) near the top of the stem. </li>
        <li>The leaf edges are <div class="tooltip">smooth<span class="tooltiptext"><img src="images/Leaf-Margin-Smooth.jpg" alt="Smooth leaf margin" title="Smooth leaf margin">Smooth leaf edges do not have any teeth.</span></div>, with no or very fine teeth.</li>
        <li>
          <div class="tooltip">Leaf venation<span class="tooltiptext"><img src="images/Veins.jpg" alt="Veins of a leaf" title="Veins of a leaf">Leaf Venation: The arrangement of veins in a leaf.</span></div>
           is <div class="tooltip">pinnate<span class="tooltiptext"><img src="images/Pinnate-Leaf-Venation.jpg" alt="Pinnate Leaf Venation" title="Pinnate Leaf Venation">Pinnate Leaf Venation:  A vein arrangement in a leaf with one main vein extending from the base to the tip of the leaf and smaller veins branching off the main vein.</span></div>, meaning that there is one main <div class="tooltip">vein<span class="tooltiptext"><img src="images/Veins.jpg" alt="Veins of a leaf" title="Veins of a leaf">Vein: A vessel that conducts nutrients, sugars, and other substances throughout plant tissues; usually associated with leaves. The arrangement of veins in a leaf is called the venation pattern.</span></div> running from the base to the tip and secondary veins branching off at intervals.</li>
      </ul>

 

Here is my css code:  
 

        /* Tooltip container */
.tooltip {
    position: relative;
    display: inline-block;
    border-bottom: 1px dotted black; /* If you want dots under the hoverable text */
}

/* Tooltip text */
.tooltip .tooltiptext {
    visibility: hidden;
    width: 200px;
    background-color: #000;
    color: #fff;
    text-align: left;
    padding: 5px;
    border-radius: 4px;
    font-size: 14px; 

    /* Position the tooltip text */
    position: absolute;
    z-index: 100;
    bottom: 100%;
    left: 50%; 
    margin-left: -100px;

    /* Fade in tooltip */
    opacity: 0;
    transition: opacity 1s;
}

/* Tooltip arrow */
.tooltip .tooltiptext::after {
    content: "";
    position: absolute;
    top: 100%;
    left: 50%;
    margin-left: -5px;
    border-width: 5px;
    border-style: solid;
    border-color: black transparent transparent transparent;
}

/* Show the tooltip text when you mouse over the tooltip container */
.tooltip:hover .tooltiptext {
    visibility: visible;
    opacity: 1;
}
.tooltip img {
  float:left;
  margin:0px 8px 8px 0;
  width: 200px;
    border-radius: 4px;
}

 

I have two problems:

1.    The tooltips only work when they are inserted within an ordered list.  When I try to insert a tooltip in a paragraph, I get an unwanted line break.  I have fiddled around with the css, to no avail.  (I can provide a screen shot, if needed.)

2.    The tooltips as currently configured work fine on all six of my desktop browsers (Chrome, Firefox, Opera, Safari, Edge, Internet Explorer), opening as desired on mouseover.  The tooltips also work fine on two of the browsers on my iPad (Opera Mini and Firefox), opening on touch.  However, the tooltips do not work at all on the iPad in either Safari or Chrome; when I touch the target term, nothing happens.  I tried this out on some iPad emulators, and the tooltips worked, but they didn’t work on the actual iPad for either Safari or Chrome.  

Your tooltip examples work beautifully on all browsers on both my desktop and iPad, so it’s something I am doing wrong.  I have searched the forum for an answer, searched the internet, and fiddled around with the code for days, to no avail.  Please help!

Thanks, ellen
 

Share this post


Link to post
Share on other sites

IF it works in ipad with tutorial example, I would go through each of  your additional code and disabling with web developer tools or commenting out, try reinstating one at a time to identify the code which is causing the problem.

  • Like 1

Share this post


Link to post
Share on other sites

Thank you so much for this suggestion!  It pointed me in the right direction, which is (as I understand it) to try to hold everything constant and start changing my code one piece at a time to try to identify what it is in my code that has been messing up my tooltips.  Before I did that, however, I decided to see whether I could replicate the problems I am encountering on my web site in a brand new page using the model code exactly as I got it from the tutorial and without any of my existing styles.  My logic:  if I could not replicate the problems on the test page, that would mean that it was either something (1) I had introduced when adjusting the tooltip code for my purposes, or (2) something in my style sheet that was fighting with the code from the tooltip tutorial.  If I was unable to replicate the problems, it would mean that I had to begin a process of trial and error to find out what in my code was messing up the tutorial code.  If I was able to replicate the problem, it would mean that it was something in the tutorial code.

Well, I created a brand new page that used the tooltip tutorial code.  That page is here:  http://wildadirondacks.org/Tooltip-Test.html

As you can see, the problems I have been struggling with on my Starflower page were EXACTLY replicated on the test page.

  1. Putting a tooltip in a paragraph resulted in an unwanted line.  Putting a tooltip in an unordered list worked fine.  (Same as in my Starflower page)
  2. The tooltips on the test page worked fine on my desktop (all six browsers) and on two of my iPad browsers (Opera Mini and Firefox).  The tooltips did not work at all on the iPad in either Chrome or Safari.  (I touched the target text and nothing happened.)

So, following the logic outlined above, I conclude that the problem is probably in the tutorial code.  I say "probably" because I might have unwittingly introduced something weird in the code when I cut and pasted into the test document.  This is not my area of expertise; I am primarily a researcher and writer and making unwitting (but fatal) errors while coding is a way of life for me.

Why does the tutorial code from the W3Schools site work on iPad on Chrome and Safari?  I don't know.  It may be something in the W3Schools style sheet.  Does the tutorial code work in plain old paragraphs for the tutorial pages on the W3Schools site?  I don't know, because I could not find an example  of a tooltip inside a para on the W3Schools site.  

So, despite your useful suggestion that led to this experiment, I am still in need of help.  

What can I do to the code on my Starflower page to make the tooltips work in (1) paragraphs (as well as unordered lists) and (2) in Chrome and Safari on my iPad? 

Ellen

Here is my html:

<body style="text-align:center;">

<h2>Tooltip</h2>

<div class="tooltip">Hover over me
  <span class="tooltiptext">Tooltip text</span>
</div>
        <p>This is paragraph one.  In this paragraph, I am just going to type for a while, to demonstrate what a paragraph looks using the body style in the example provided at W3Schols.  Just a plain old paragraph.  It's going to be centered on the page, because that's the style set up in the example I am following.  OK, now I am tired of typing, so I am going to end my pararaph. 
        </p>
    <p>This is paragraph two.  I am trying to see whether this tooltip will work inside a paragraph.  So I am just going to type and type and type, and then eventually insert a tooltip, followed by more typing.  Here is my tooltip: <div class="tooltip">Hover over me
  <span class="tooltiptext">Tooltip text</span>
</div>OK, now I am going to type a little bit more, to finish my fake paragraph.  As you can see, the tooltip inserts an unwanted line just before the tooltip target text.  The tooltip itself works, but it has messed up my paragraph.
        </p>
        
<p>Now, I am going to type in a second paragraph, followed by an unordered list, to see whether the tooltip will work with the unordered list: </p>
<ul>
          <li>          This is the first bullet of my unordered list.  </li>
          <li>This is the second bullet.  </li>
          <li>This is the third bullet. In this bullet, I am going to include a tooltip. Here is my tooltip: <div class="tooltip">Hover over me
  <span class="tooltiptext">Tooltip text</span>
</div> Thus ends my tooltip. </li>
          <li>This is the fourth bullet. </li>
</ul>
    <p>This is the rest of my paragraph.  I am going to type in a few more sentence to fill out the paragraph.  As you can see, the tooltip works perfectly inside an unordered list.  It does what a tooltip is supposed to do, and it doesn't insert an unwanted line. This test page mirrors exactly what my<a href="adirondack-wildflowers-starflower-trientalis-borealis.html"> Starflower page</a> did when I tried to inserts tooltip in a paragraph.  The tooltips inside an unordered list worked fine, but the tooltips inside a plain old paragraph inserted an unwanted line break. </p>
    <p>One additional point: When I deployed this page to the server, and tried it on my iPad, the tooltips behaved exactly as they behaved on my Starflower page.  That is, the tooltips appear obediently on touch with the Firefox and Opera Mini browsers, but do not appear at all with the Safari and Chrome browsers.  </p>
</body>
</html>

Here is my css:

<style>
.tooltip {
    position: relative;
    display: inline-block;
    border-bottom: 1px dotted black;
}

.tooltip .tooltiptext {
    visibility: hidden;
    width: 120px;
    background-color: #555;
    color: #fff;
    text-align: center;
    border-radius: 6px;
    padding: 5px 0;
    position: absolute;
    z-index: 1;
    bottom: 125%;
    left: 50%;
    margin-left: -60px;
    opacity: 0;
    transition: opacity 1s;
}

.tooltip .tooltiptext::after {
    content: "";
    position: absolute;
    top: 100%;
    left: 50%;
    margin-left: -5px;
    border-width: 5px;
    border-style: solid;
    border-color: #555 transparent transparent transparent;
}

.tooltip:hover .tooltiptext {
    visibility: visible;
    opacity: 1;
}
</style>

 

Share this post


Link to post
Share on other sites

I don't have ipad so i can't test it.

I did notice that you have a block element div within a paragraph? THIS is NOT allowed, and being a block element it WILL force a new line. The only elements allowed in paragraph element are inline elements i.e span, strong, a (anchor) etc.

  • Like 1

Share this post


Link to post
Share on other sites

In that case, how can I create a tooltip within a paragraph, vice an unordered list?  I use a lot of unordered lists to present information on certain aspects of each plant, in part because usability studies advise doing so, to break up the text in chunks.  However, there are some cases where I would like to put a tooltip in the middle of a paragraph.  Is there a way to do that, without introducing an unwanted line break?  

Share this post


Link to post
Share on other sites

Use inline elements inside the paragraph, like  <span> instead of  <div>.

  • Like 1

Share this post


Link to post
Share on other sites

Well, that was easy!  Thank you so much!  You have solved the problem of tooltips within paragraphs.

I still need to solve the problem of the tooltips not working at all on my iPad on Chrome or Safari. Foxy, I know you don't have an iPad, but is there someone who does that can point me in the right direction?

Thanks again!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×