Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>So you're trying to get CSS sprites - background images with adjustable background positions - working with html <code>&lt;map&gt;</code> <code>&lt;area&gt;</code> elements? Tricky but possible. </p> <h2><a href="http://jsbin.com/urOsoku/8/edit" rel="nofollow noreferrer">DEMO on jsbin</a></h2> <p>This is tested in Firefox, Chrome, Opera and Safari (August 2013), plus Internet Explorer 7, 8, 9 and 10.</p> <hr> <p>You basically just need an <code>&lt;img&gt;</code> with an <strong>invisible but valid</strong> <code>src</code> attribute that <strong>doesn't cause the browser to show its 'broken image' icon</strong>. </p> <p>My preferred way is this, a 1px by 1px transparent gif, base64 encoded so no actual .gif file is needed: </p> <pre><code>src="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAIC‌​RAEAOw==" </code></pre> <p>There are a few other suggested methods at <a href="https://stackoverflow.com/questions/5775469/whats-the-valid-way-to-include-an-image-with-no-src">"What's the valid way to include an image with no src?"</a> but all the others I tried had at least one issue. This just worked fine.</p> <p>Then it's just the usual stuff:</p> <ul> <li>fixed height and width, ideally through css</li> <li>a background image with background position set, like in normal sprite images.</li> <li>a <code>usemap</code> attribute just like normal when making an image map (like <code>usemap="#someArea"</code> with a <code>#</code> if you want old IE support - as normal).</li> <li>normal <code>&lt;map&gt;</code> element with id corresponding to <code>img</code>'s <code>usemap</code>, containing <code>&lt;area&gt;</code> elements</li> </ul> <hr> <p>If your goal is to have multiple images with associated areas from different locations on the same sprite sheet, you might run into this problem: <a href="https://stackoverflow.com/questions/4536306/overlapping-images-w-image-maps-obstructing-each-other">Overlapping images w/ image maps obstructing each other</a>. The simple solution suggested there works well with image maps: assign your <code>&lt;map&gt;</code> to one completely transparent image as above but with no background image, keep it above all other images, then have the images as regular image sprites underneath.</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. 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