首页 > 解决方案 > HTML 图像不会链接到页面

问题描述

有一种愚蠢的问题,即我的 HTML 图像不会链接到页面并且不会显示为可点击。我有一个购物车和一个购物车图标,显示购物车中的商品数量。图像包含在 CSS 中。我尝试z-index一直设置,但什么也没发生。不确定我是否遗漏了一些明显的东西。对此相当新,因此感谢您的帮助!以下是我的代码:

.cart {
  background-color: #E55F5F;
  background-image: url(images/shoppingcart.png);
  background-size: contain;
  color: white;
  height: 60px;
  width: 60px;
  line-height: 60px;
  text-align: center;
  margin-top: -20px;
  border-radius: 50%;
  position: fixed;
  z-index: 1000;
  overflow: hidden;
}
<li>
  <div class="cart">
    <a href="/homework_6/cart.html"></a>
  </div>
  <div id="quantityCount">0</div>
</li>

标签: htmlcss

解决方案


你的标签没有任何价值,所以它可以被点击。

你可以像下面这样使用它:

<li>
   <div class="cart"><a href="/homework_6/cart.html">cart</a></div>
   < id="quantityCount">0</div>
</li>

否则,如果您想将计数显示为 clicable

<li>
   <div class="cart"><a href="/homework_6/cart.html"><span id="quantityCount">0</span></a></div>
</li>

推荐阅读