Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here's another approach, and in my opinion far superior to using a map or excessive JS. Place <code>&lt;div&gt;</code> elements on top of the element with the background-image and have HTML and CSS do the heavy lifting for you.</p> <p><img src="https://i.stack.imgur.com/67bgY.png" alt="Image of my example"></p> <p><a href="http://jsfiddle.net/ycSLQ/" rel="nofollow noreferrer">See it on JSFiddle</a></p> <p><strong>HTML</strong></p> <p>The HTML should seem pretty each enough to understand, we create <code>&lt;div&gt;</code>s with the class <code>hotspot</code> and rely on certain things being present. Namely <code>.text</code> (to show digit), <code>.hover-popup</code> (to show on hover) and <code>.click-popup</code> (which is inside <code>.hover-popup</code> and is shown when clicked).</p> <pre><code>&lt;div id="hotspot1" class="hotspot"&gt; &lt;div class="text"&gt;1&lt;/div&gt; &lt;div class="hover-popup"&gt; I was hovered! &lt;div class="click-popup"&gt; I was clicked on! &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;div id="hotspot2" class="hotspot"&gt; &lt;div class="text"&gt;2&lt;/div&gt; &lt;div class="hover-popup"&gt; I was hovered! &lt;div class="click-popup"&gt; I was clicked on! &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; </code></pre> <p><strong>CSS</strong></p> <p>This is where most of the magic happens, see the comments for further explanation.</p> <pre><code>/* These two position each hotspot */ #hotspot1 { left:15%; /* we could use px or position right or bottom also */ top:20%; } #hotspot2 { left:35%; top:25%; } /* General styles on the hotspot */ .hotspot { border-radius:50%; width:40px; height:40px; line-height:40px; text-align:center; background-color:#CCC; position:absolute; } .hotspot .text { width:40px; height:40px; } /* Show the pointer on hover to signify a click event */ .hotspot .text:hover { cursor:pointer; } /* hide them by default and bring them to the front */ .hover-popup, .click-popup { display:none; z-index:1; } /* show when clicked */ .hotspot.clicked .click-popup { display:block; } /* show and position when clicked */ .hotspot:hover .hover-popup { display:block; position:absolute; left:100%; top:0; width:300px; background-color:#BBB; border:1px solid #000; } </code></pre> <p><strong>JavaScript (with jQuery)</strong></p> <p>Unfortunately you're going to have to use some JavaScript for the clicking part as CSS doesn't have a 'clicked' state (outside of hacks with checkboxes). I'm using jQuery because it's dead easy to do what I want.</p> <pre><code>$(document).ready(function () { $('.hotspot').click(function () { $(this).toggleClass('clicked'); }); }); </code></pre> <p><strong>Creating the arrow</strong></p> <p>Over at <a href="http://css-tricks.com/speech-bubble-arrows-that-inherit-parent-color/" rel="nofollow noreferrer">css-tricks</a> you can find a tutorial for attaching an arrow to a element using the <code>:before</code> and/or <code>:after</code> pseudo-elements. You can even 'simulate' a border around them by placing the <code>:after</code> element on top of the <code>:before</code>. But yea, lots of resources on how to do this.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload