Im trying to figure out the best way to make that picture interactive
(they can click on a part of the house and a link will open up to another page explaining what the purpose of that room is)
Should I make the position of the floor-plan relative, then absolutely position a link? Is there a better way to go about this?
Wow I had forgotten about the map element! I got inspired to look into it and found this site which might help you generate maps: https://www.image-map.net/ It lets you draw the areas you want to make clickable, give it a link, and a tooltip. It then generates the code you need, and is not reliant on JavaScript.
It would still be helpful to visit the docs Ray linked to so that you understand how it works behind the scenes
Another option, if you use an SVG (which lends itself to this kind of image), you can wrap SVG shapes in anchor tags to have shaped links within the image.
ok, I’m not smart enough to use SVG to recreate a floorplan. I think I need to make an image the map element. Since i’ll be using bootstrap, I can make it scalable by adding this class
In coothead’s excellent example he uses the original image as a background and the svg is only simple polygons to define the room outlines for the links. So there was no need to recreate the whole image in svg.
Though an svg would make a very crisp, scalable image.
I have not experimented with the map element yet, so I don’t know how it scales, or more importantly how the areas and their coordinates scale within it. But Bootstrap is only a grid-type framework, working in rows and columns. Elements placed by coordinates are handled differently.
The css could be simplified further to make the image “fluid” rather than adaptive, which is my preferred method of responsive design.
Simply swap width:50em for max-width:50em on the #floor-plan and remove the height rule.
This is enough to make the image fluid, so you can now remove all the media queries from the bottom of the css.
I was actually surprised when it just worked, taking the height out. I was expecting to have to do something like that to set the height.
But of course I did not take the time to test across browsers.
@cootheads example is the method I would recommend but just for old times sake and because the areas are mostly rectangular you can absolutely place the anchors over the respective parts of the image like this:
That is the way I would have done it before svg was available and if you needed to support very old browsers. Of course this only works if areas are mostly rectangular.
Do the spans d1, d2, and d3 account for the non-rectangular surface area? The dining area list item has all the three spans, whereas the patio and living room list items do not have spans (They are a bit non-rectangular).
I don’t see how the shapes are accounted for, but maybe that’s just me not knowing any better. Ah, I see that you used a :before target for .living and .patio. Good show.
It’s really hard to do this using image maps that don’t result in bloated code, but I’m not the maestro.