html - 图片按钮在 HTML5/CSS3 中不可点击

标签 html image css button

我在让图像在我的网站上可点击时遇到问题。我所有带有链接的标准按钮都可以正常工作。下面我将粘贴与相关按钮相关的 CSS 和 HTML5 代码。出于显而易见的原因,我省略了实际链接。

.button3 {
  background-image: url("donate.png");
  background-size: cover;
  background-position: center;
  border-radius: 25px;
  cursor: pointer;
  width: 200px;
  height: 60px;
  margin-left: 500px;
  margin-right: 5px;
  margin-top: 40px;
}
<div class="button3">
  <a href="link" class="button3"></a>
</div>

最佳答案

您可以改为将 div 按钮包裹在 anchor 标记中,这样您的 anchor 标记将拉伸(stretch)为其内容的宽度和高度,从而使您可以点击整个 div。

请看下面的例子:

.button3 {
  background-image: url("https://cdn.sstatic.net/Sites/stackoverflow/company/img/logos/so/so-icon.svg?v=f13ebeedfa9e");
  background-size: cover;
  background-position: center;
  border-radius: 25px;
  cursor: pointer;
  width: 200px;
  height: 150px;
  /*margin-left:500px;
  margin-right:5px;*/
  margin-top: 40px;
}
<a href="link">
  <div class="button3">
  </div>
</a>

关于html - 图片按钮在 HTML5/CSS3 中不可点击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55614984/

相关文章:

css - 图像未分布在列数上

java - 使 TextView 中的图像具有固定大小 - Android

html - 如何在同一列的顶部和底部放置相同的图像?

html - Chrome TD 高度

jquery - 如何使用 while 循环在 for 循环中更新 innerHTML?

jquery - 如何在 JQuery 中打开具有相同类的单独工具提示

html - 无论如何,Bootstrap 导航栏都不会居中

html - 这个数据是什么类型的结构?

html - Web应用程序上的登录页面?

html - 使图像组表现为一个 block (例如 :resize together)!