Using CSS to create clickable areas on an image

Here is an example image:

https://i.sstatic.net/EerkN.jpg

This image shows a desk with various elements, and I am looking for a way to make parts of the image interactive.

For example, clicking on the monitor would take you to a specific link, and clicking on the speaker would take you to a different link.

The challenge is to achieve this using only CSS and HTML without relying on JavaScript or any other tools.

Is this even possible?

Thus far, I have only come across websites offering interactive SVG maps...

I am aware that I can use:

<img src="https://i.sstatic.net/EerkN.jpg" usemap="#menu_header" />
<map name="menu_header">
  <area coords="117,214,271,266" href="X" shape="rect" />
  <area coords="272,214,411,266" href="X" shape="rect" />
  <area coords="412,214,635,266" href="X" shape="rect" />
  <area coords="636,214,816,266" href="X" shape="rect" />
</map>

However, I would prefer to use more intricate shapes that match the actual objects like the speaker and monitor, rather than just rectangles.

Answer №1

To create custom shapes, you can utilize the poly shape derived from Polygon.

Polygon

The Polygon shape requires multiple pairs of coordinates to define the vertices of the shape. These coordinates can create various polygon shapes with sloping lines. Each coordinate is represented by its horizontal and vertical positions, listed sequentially with commas. The final pair of coordinates can optionally match the first pair. Here is an example:

shape="poly" coords="217,305,218,306,218,306,228,316,243,316,243,325,229,325,229,322,217,310"

There are numerous online tools for creating image maps that can assist you in generating these shapes.

Answer №2

If you're looking to easily and quickly obtain coordinates for each polygon on a map, consider using a mapping generator tool. One such tool that I've personally used is the Imagemap-generator. All you have to do is draw the specific areas you want to link, like I did in this example: https://gyazo.com/7ddba6578cd1ebfe4f31088d40f1cf06, and you'll receive the necessary code.

For instance, for a speaker, the code would look like this:

<img src="url/to/your/image.jpg" alt="" usemap="#Map" />
<map name="Map" id="Map">
    <area alt="" title="" href="#" shape="poly" coords="80,895,134,855,194,813,239,766,275,726,319,669,364,647,397,645,442,666,476,705,501,746,513,805,527,856,550,921,578,979,608,1039,604,1107,584,1144,544,1185,454,1218,285,1216,134,1151,42,1033,45,944,174,824" />
    [...]
</map>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Utilizing JQuery to modify the element's id and trigger a function upon clicking

There is an element with a specific ID that I have changed. However, even after changing the ID and clicking on the element with the new ID, it still triggers the function associated with the old ID. $('#1st').click(function(){ $('#1s ...

Angular's inline style manipulation fails to function in IE browser

I am facing an issue with setting the position of a div based on the return value of a function in an angular controller Although it works fine in FireFox and Chrome, Internet Explorer is interpreting {{position($index)}}% as a literal string value, resul ...

Tips for controlling image sizes on larger devices while maintaining the appearance on Retina displays

I've been searching on the internet, but I got lost in complex explanations. I thought maybe someone here could help me out. :) I have a website with both mobile and desktop versions. Most of it looks good on different devices but there are some elem ...

What are some ways to enable text highlighting when it is disabled?

I've encountered an issue with text highlighting in my asp.net web application when using the latest versions of FireFox and Google Chrome. Strangely, pressing CTRL+A also does not work for all input fields. I haven't had the opportunity to test ...

How to Fetch Information from Database and Save it as a Variable in PHP

I am trying to extract the data stored in the level column of my database and assign it to a variable with the value 0. Here is the code snippet I have written to achieve this, where I fetch the data from the database and store it in a variable named $lev ...

Utilizing Selenium for web scraping on Google Maps consumes an excessive amount of data

Scraping travel times from Google Maps is a task I have successfully accomplished. The code below scrapes travel times between 1 million random points in Tehran utilizing multiprocessing for efficiency. You can run the code provided in a terminal environme ...

"Adjusting the size of a jQuery dialog for optimal viewing on

I am currently working on designing an HTML page that is responsive for both mobile and desktop browsers. One issue I am encountering involves a jQuery dialog that I need to scale properly to fit the page. I believe the problem lies within these lines of ...

Effortlessly fill dropdown menus with data from JSON files

I've been using this jQuery code successfully, but I recently needed to add 3 more field columns to the JSON. My goal is to have the HTML select drop-downs dynamically change based on the data from the previous drop-down. Additionally, my current jQue ...

Tips for properly formatting a fixed table header

I'm currently facing an issue with the sticky header style in my data table. I have created a simple Angular component along with a specific directive: sticky.directive.ts @Directive({ selector: '[sticky]' }) export class StickyDirecti ...

Is it possible to designate a specific font family for italic font style and a different font family for regular font styles in VSCode?

Is it possible to use the "Operator Mono" font only for italic style and another font, such as "Fira Code," for other styles like bold, regular, semibold, etc. in VSCode? I attempted to change the font family to: "editor.fontFamily": "'Operator Mono ...

What could be causing the slider element to select the incorrect value in Firefox and Internet Explorer?

Attempting to test a slider control on a webpage using Selenium, here is the HTML: <div class="slider theme1 ui-slider ui-slider-horizontal ui-widget ui-widget-content ui-corner-all" data-action="Slider" data-step="True" da ...

Out of nowhere, JavaScript/jQuery ceased to function

Everything was running smoothly on my website with jQuery Ui until I changed the color, and suddenly everything stopped working. Any ideas why this happened? I even tried writing the JavaScript within the HTML file and linking it as a separate .js file, bu ...

I'm looking for a method to trigger onChange() specifically on Internet Explorer using only JavaScript, HTML, and CSS without relying on jQuery

Looking for a way to utilize onChange() only on Internet Explorer using Javascript, HTML, CSS (No Jquery). My current code successfully sends the input to my function upon onChange(), but it seems to work smoothly on Chrome and not on IE. Is there a meth ...

PHP Linking Style Sheets

I am exploring the use of an HTML Diff Tool in PHP, specifically looking at this one: https://github.com/rashid2538/php-htmldiff. I am fetching the content of both pages using cURL and passing it to the HTML-Diff tool. It works perfectly fine, but there is ...

Guide to centering the navigation bar within a container using Bootstrap 4

I'm looking to center the navbar on my webpage. How can I style it so that it appears in the middle of the page? Currently, it's aligned with the left side of the page. section class="navbarSection"> <div class="contain ...

SVG Error: You might require a suitable loader to manage this file format, as there are currently no configured loaders to handle it

Encountered an issue with my application - everything was functioning properly until I executed npm run audit fix force. Now, I am receiving the following error message related to an SVG file. The error indicates that there may be a need for a loader to h ...

"Efficiently handle online submissions: Use Django to submit a form and instantly display the outcome

I have an urgent task to develop a web page where users can input data, and the backend will perform calculations and display the result below the input field on the same page (similar to checking online air ticket prices). I am new to Django and HTML. Be ...

Deactivate the button until the input meets validation criteria using Angular

What I'm trying to achieve is to restrict certain input fields to only accept integer or decimal values. Here's the code snippet that I currently have: <input type="text" pattern="[0-9]*" [(ngModel)]="myValue" pInputText class="medium-field" ...

Ways to adjust the dimensions of a textarea based on character count

When attempting to utilize the cols and rows attributes of the <textarea> element in order to set the width and height in characters, I have encountered issues even without implementing CSS. Take a look at this example: link I have configured a 5x5 ...

HTML CSS margins are used to create white spaces at the edges of a webpage

My website is displaying white spaces on the edge and I want it to look seamless like this: Does anyone know where I went wrong? ...