Reputation: 55
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.
Upvotes: 4
Views: 18779
Reputation: 5809
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
Upvotes: 1
Reputation: 8412
Below are the global attributes for <map>
and don't think It is what you need to do the job.
accesskey
class
contenteditable
contextmenu
data-*
dir
draggable
dropzone
hidden
id
lang
spellcheck
style
tabindex
title
translate
Some of my observations:
img {
border:solid;
width:100% ;
height:100%;
}
map {
position:absolute;
}
<!DOCTYPE html>
<html>
<body>
<p>Click on the sun or on one of the planets to watch it closer:</p>
<map name="planetmap">
<area shape="rect" coords="0,0,82,126" alt="Sun" href="sun.htm">
</map>
<img src="https://encrypted-tbn2.gstatic.com/images?q=tbn:ANd9GcRTNx0KWm64q1n3aTNvA6xilTrtDRgTI0wPlxb13mcNn55nahKw" alt="Planets" usemap="#planetmap">
</body>
</html>
body{
position:relative;
background:url("https://encrypted-tbn3.gstatic.com/images?q=tbn:ANd9GcQfqyqPka3zuGaR9sVDXDcfHMyNrLQnz3QFkaXcWCc8WX_S_14R");
background-size:cover;
border:solid;
display:block;
margin:auto;
width:100wh;
height:100vh;
cursor:pointer
}
#full_blown{
width:100wh;
height:100vh;
}
<body onclick="location.href='www.google.com'"></body>
<h1>THIS IS SOME </h1>
<p>
There was a cow called boy
</p>
Upvotes: 0