2

I have a simple question which I can't seem to solve.

#tps_block {
  height: 45px;
  width: 940px;
}
#tps_point1 {
  width: 351px;
  background: url("http://www.jenierteas.com/templates/default/images/hp_usp.png") 0 0 no-repeat;
  text-indent: -9999px;
  display: block;
  height: 100%;
  float: left;
}
#tps_point1:hover {
  background: url("http://www.jenierteas.com/templates/default/images/hp_usp.png") 0 -45px no-repeat;
}
#tps_point2 {
  width: 284px;
  background: url("http://www.jenierteas.com/templates/default/images/hp_usp.png") -351px 0 no-repeat;
  text-indent: -9999px;
  display: block;
  height: 100%;
  float: left;
}
#tps_point2:hover {
  background: url("http://www.jenierteas.com/templates/default/images/hp_usp.png") -351px -45px no-repeat;
}
#tps_point3 {
  width: 305px;
  background: url("http://www.jenierteas.com/templates/default/images/hp_usp.png") -677px 0 no-repeat;
  text-indent: -9999px;
  display: block;
  height: 100%;
  float: left;
}
#tps_point3:hover {
  background: url("http://www.jenierteas.com/templates/default/images/hp_usp.png") -677px -45px no-repeat;
}
<div id="tps_block">
  <div id="tps_point1"><a href="#">Point 1</a>
  </div>
  <div id="tps_point2"><a href="#">Point 2</a>
  </div>
  <div id="tps_point3"><a href="#">Point 3</a>
  </div>
</div>

The idea is that there are 3 images side by side, and when the mouse hover's over each image, the image changes to a highlighted one, and the image is clickable too, so that the user is taken to some other place when the image is clicked.

I have managed to apply the hover effect, but I can't get the linking to work.

Can someone help me out ?

JSFiddle: http://jsfiddle.net/ahmadka/Fjmnt/

4

3 回答 3

9

如果您能够更改 HTML,只需丢失内部div标签并将完全相同的样式应用于链接本身:

<div id="tps_block">
  <a href="#" id="tps_point1">Point 1</a>
  <a href="#" id="tps_point2">Point 2</a>
  <a href="#" id="tps_point3">Point 3</a>
</div>

更新了 jsFiddle:http: //jsfiddle.net/Fjmnt/7/

于 2013-09-07T20:14:09.740 回答
2

如果您无法修改 HTML 的最佳解决方案。添加以下 CSS。

#tps_block a {
    display: block;
    width: 100%;
    height: 100%;
}

这将填充<a>使整个div可点击。

jsFiddle 演示

于 2013-09-07T20:12:50.310 回答
1
<div id="tps_block">
  <a href="#"><div id="tps_point1"></div></a>
  <a href="#"><div id="tps_point2"></div></a>
  <a href="#"><div id="tps_point3"></div></a>
</div>
于 2013-09-07T20:13:58.663 回答