12

What is an alternative to using image maps? I saw a question recently and someone said, "Why are people still using image maps?" and I wanted to know a good CSS or JavaScript solution to see for myself if its better to use than an image map.

3

5 Answers 5

7

CSS is the way to go when working with image maps. You can easily position a link with desired width and height over any area of the image by changing top left width height values.

Check a working example at http://jsfiddle.net/DBvAY/1/

In the example, Hover over the babies face or the red light in the image. To change the position of the anchors all you need to do is modify the top and left properties of #pos1 and #pos2. Same goes for width and height of the bounding box. All done with CSS with no javaScript.

5
  • 18
    This is all good and well but how would you create other shapes then rectangular shapes for your clickable areas?
    – EasyCo
    Commented Jan 20, 2012 at 0:14
  • 4
    Moving an invisible anchor of an image is not a viable alternative to an image map, especially since image maps can contain irregular shapes. Commented Mar 12, 2013 at 15:36
  • 1
    This is not really a viable option when image mapping is necessary. Using a CMS it is not always possible for the content editor to have access to x y co-ordinates or height and width of an element. Commented Nov 5, 2013 at 12:45
  • More shapes here: css-tricks.com/working-with-shapes-in-web-design Find % position for scaling here: zaneray.com/responsive-image-map
    – eye-wonder
    Commented Aug 9, 2017 at 9:14
  • This answer is linked to a jsfiddle that seems not to work any more. Probably because the image no longer exists or the connection is refused by the server.
    – Aaron
    Commented Nov 27, 2020 at 19:57
2

you only need to put the ID's on the anchors, the divs are not required.

2

If your website is responsive, you might want to try using SVG as an excellent alternative to image maps.

SVGs can easily be made responsive and also respond to hover effects, etc.

This is a nice article that discusses the matter.

1
  • The link is broken. Can you help us to find the article?
    – Mawg
    Commented Feb 26, 2017 at 14:28
1

As the Hussein answer. I'm just adding my remarks and share with you some links in the fever of use image map.

  1. you cannot only position the image like square but also like rectangle and even polygon.
  2. you can add your desire output in a popup screen by hover the position/ and even you can perform action as well.

to get more please visit these below linkshelp full

link 1imagemapster

link 2imagemapster-solutions

you can google it as image mapster for more. thanks

0

This is extending Hussein's answer and make it scale in a responsive design. Also you can make different simple shapes from CSS with transform. To find the approximate position (%) you can get help from this page.

Here is a example:

html, div, p, a {
  font-family: arial;
}
.map-image {
  display: inline-block;
  position: relative;
  overflow: hidden;
  padding: 0;
}
.map-image img {
  width: 100%;
  height: auto;
  display:block;
}
.map-image a {
  text-decoration: none;
  padding: 5px;
  color: #FFF;
  text-shadow: 0px 0px 5px rgba(0, 0, 0, 0.5);
  margin: 0;
  font-size: 4vw;
}
.map-image a:hover {
  border: 1px solid #FFF;
  margin: -1px;
}
.map-image a.rotate {
  border-radius: 50%;
  -ms-transform: rotate(20deg); /* IE 9 */
  -webkit-transform: rotate(20deg); /* Chrome, Safari, Opera */
  transform: rotate(20deg);
}
.map-image a.rotate span {
  position:absolute;
  -ms-transform: rotate(-20deg); /* IE 9 */
  -webkit-transform: rotate(-20deg); /* Chrome, Safari, Opera */
  transform: rotate(-20deg);
  top:25%;
}
.map-image a.skew {
   border-radius: 15%;
   -ms-transform: skewX(-20deg) rotate(9deg);
   -webkit-transform: skewX(-20deg) rotate(9deg);
   transform: skewX(-20deg) rotate(9deg);
}
.map-image a.skew span {
  position:absolute;
  -ms-transform: skewX(20deg) rotate(-9deg);
  -webkit-transform: skewX(20deg) rotate(-9deg);
  transform: skewX(20deg) rotate(-9deg);
  top:12%;
  left:4%;
}
.map-image svg {
  position:absolute;
}
.map-image polygon:hover {
  stroke: #FFF;
}
.map-image .poligon-title {
  position:absolute;
  left:19%;
  top:43%;
  color: #FFF;
  text-shadow: 0px 0px 5px rgba(0, 0, 0, 0.5);
  margin: 0;
  font-size: 2.6vw;
  z-index:100;
}
<div class="map-image">
  <img src="http://cdn.frooition.com/060129/images/100_1428.JPG">
  <a href="https://www.google.com" title="Front window" style="position: absolute; left: 24.4%; top: 16.3%; width: 33.3%; height: 25.39%; z-index: 99; background-color:rgba(255,0,0,0.3);" class="skew"><span>Google</span></a>
  <a href="https://www.facebook.com" title="Seats" style="position: absolute; left: 58%; top: 0.16%; width: 28.4%; height: 26.33%;  z-index: 96; background-color:rgba(0,255,255,0.2);">Facebook</a>
  <a href="https://www.linkedin.com/" title="Wheel" style="position: absolute; left: 43%; top: 57.4%; width: 20%; height: 39.34%; z-index: 99; background-color:rgba(0,255,0,0.2);" class="rotate"><span>Linkedin</span></a>
  <svg height="auto" width="34%" style="position: absolute; left: 10%; top: 36%;  z-index: 99;" viewBox="0 0 450 600">
<a id="anchor" xlink:href="https://stackoverflow.com" target="_top">
  <polygon points="190,5 385,60 210,320 0,300 200,134 205,120 205,104" style="fill:rgba(0,0,0, 0.4);stroke-width:1" />
  Sorry, your browser does not support inline SVG.
  </a>
</svg>
<div class="poligon-title">Stackoverflow</div>
</div>

(The mixing with svg polygon is a little bit experimental)

Not the answer you're looking for? Browse other questions tagged or ask your own question.