I am creating a website for an app I developed. The background of the website in an image that I photoshopped on a desk with an iPhone on it displaying the home screen of my app. I want to image map the background image so when you click on the screen it takes you somewhere. I am aware on how to image map so I already tested the image map using the <img>
tag. It works fine; however, I want the image to have the property “background-size: cover;” so it fills the screen at all times and maintains aspect ratio, leaving no whitespace. This property only works for background images or <div>
tags; unfortunately, you can only image map on <img>
tags (I think). I have been researching this for hours. Also, my image map is a polygon so it is unique. Thank you for any help in advance.
2
Answers
Below are the global attributes for
<map>
and don’t think It is what you need to do the job.Some of my observations:
possible Solution:
Snippet Here
First of all, HTML and CSS do not have a native way of scaling image maps to different sizes. However, there are Javascript workarounds to this. See this question: Responsive image map.
The CSS
object-fit
property seems like your best option for scaling the image. However, at the time of this writing, no version of Internet Explorer (including Edge) supports this property.Really, I think the best solution is to rethink your layout. There is probably no way to solve this problem as stated in an efficient and widely-compatible way.
So, here is what I would recommend:
background-size: cover
for the background image.<a>
tag on top of the image to align with the screen or specific UI elements.Here is a simple example of this method in action: http://codepen.io/bvisness/pen/pgrGBr