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.
-
Here is the question that was related to this: stackoverflow.com/questions/745110/…– Kieran AndrewsCommented Mar 4, 2011 at 6:41
-
I am curious, why not use an image map?– L84Commented May 28, 2012 at 18:22
-
because they seem to be unsupported on the iphone– benedict_wCommented Nov 12, 2012 at 19:55
5 Answers
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.
-
18This is all good and well but how would you create other shapes then rectangular shapes for your clickable areas?– EasyCoCommented Jan 20, 2012 at 0:14
-
4Moving 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
-
1This 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 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.– AaronCommented Nov 27, 2020 at 19:57
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.
As the Hussein answer. I'm just adding my remarks and share with you some links in the fever of use image map.
- you cannot only position the image like square but also like rectangle and even polygon.
- 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 1
imagemapster
link 2
imagemapster-solutions
you can google it as image mapster for more. thanks
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)