使用背景图像将热点添加到DIV

Eri*_*rik 1 html css

是否可以在div中添加带有背景图像的热点?

非常感谢.

埃里克

Mar*_*rko 6

可以肯定的是,只需在相对定位的div(使用背景图像)内使用绝对定位的链接.

示例HTML

<div class="hotspot-container">
    <a href="some-href-for-the-hot-spot" class="hotspot">&nbsp</a>
</div>
Run Code Online (Sandbox Code Playgroud)

CSS

.hotspot-container {
  width: 200px; height: 200px;
  position: relative;
  background: url(some-background-image) no-repeat;
}
  .hotspot-container .hotspot {
    width: 10px; height: 10px;
    position: absolute;
    top: 20px; /* Top coord of hotspot (relative to parent, bottom: 20px is also valid) */
    left: 20px; /* Left coord of hotspot (right: 20px is also valid); */
  }
Run Code Online (Sandbox Code Playgroud)