The hitbox of the SVG imgI cant figure out how to get my Image to be the Hitbox of the image since it has curves and corners its not square.
I have tried it like this with svg tags aswell and it always ends up with the square hitbox I dont know how to continue. The Hitboxes should be the size of the IMG so that when i hover over it, it lights up
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="home.css">
<script defer src="index.js"></script>
<title>asdasd</title>
</head>
<body>
<div class="header">
<div class="header-content">
<div class="dropdown">
<img src="../Icons/menu.png" class="menu">
<div class="dropdown-content">
<a href="#">Link 1</a>
<a href="#">Link 2</a>
<a href="#">Link 3</a>
</div>
</div>
<img src="Imgs/logo.jpeg" class="logo">
</div>
</div>
<main>
<object type="image/svg+xml" data="Imgs/9wdpMq01.svg">
</object>
<img src="Imgs/Ebene-3-Kopie.svg" alt="Test">
</main>
</body>
2
Answers
you can use the
<map>
and<area>
.Replace the
x1, y1, x2, y2, x3, y3, ...
coordinates in the element with your SVG coordinates. Make sure to addshape="poly"
to the area tag!If you can’t use an inline svg you can create a responsive
clip-path
and apply it to your<img>
element.I concatenated all paths to a single compound path and used yoksel’s clip-path generator to get a scaled clip-path.
Further reading: