首页 > 解决方案 > 为什么光标在按钮上没有改变

问题描述

我不确定为什么光标不会变为按钮上的指针。我看到一些解决方案说这是因为z-index. 但是当我尝试使用 时z-index,它仍然不起作用。

.upload-btn-wrapper {
  position: relative;
  overflow: hidden;
  display: inline-block;
}

.btn {
  border: 2px solid gray;
  color: gray;
  background-color: white;
  padding: 8px 20px;
  border-radius: 8px;
  font-size: 20px;
  font-weight: bold;
}

.upload-btn-wrapper input[type=file] {
  font-size: 100px;
  position: absolute;
  left: 0;
  top: 0;
  opacity: 0;
  cursor: pointer;
}
<div class="upload-btn-wrapper">
  <button class="btn">Upload a file</button>
  <input type="file" name="myfile" />
</div>

谢谢你的帮助。

我从这个codepen作弊:

https://codepen.io/adambene/pen/xRWrXN

标签: htmlcss

解决方案


尝试将cursor: pointer;属性添加到文件的输入类型。这是文件输入类型的最终片段。

.upload-btn-wrapper input[type=file] {
  font-size: 100px;
  position: absolute;
  left: 0;
  top: 0;
  opacity: 0;
  cursor: pointer; /*this is what you need*/
}

让我知道这是否有效。


推荐阅读