【问题标题】:How can I hide a button on hover? [closed]如何在悬停时隐藏按钮? [关闭]
【发布时间】:2021-11-13 22:34:21
【问题描述】:

我正在尝试使用下面的代码在悬停时隐藏我的 .dwBtn 类按钮,但它不起作用。

.dwBtn {
  border: none;
  outline: 0;
  display: inline-block;
  padding: 8px;
  color: white;
  background-color: rgb(0, 180, 0);
  text-align: center;
  cursor: pointer;
  width: 100%;
  font-size: 18px;
}

.dwBtn:hover {
  display: none;
}
<button class="dwBtn">Test</button>

我在 Google 和 StackOverflow 上进行了搜索,但找不到解决方案。我试过改变不透明度,像这样:

opacity: 0;

但据我所知,它仍然没有做任何事情。好像哪里有错别字,但我找不到。

【问题讨论】:

  • 这似乎工作正常?
  • 不,看看昆汀的回答——现在问题解决了:)
  • 他们似乎都做同样的事情,虽然使用不同的技术,但外观是一样的

标签: html css button hide


【解决方案1】:

当元素未显示时,您无法将其悬停,因此规则停止应用,因此立即弹回。

按照您的建议使用不透明度会起作用,但由于您已经修复了错字,它似乎不起作用。

.dwBtn {
  border: none;
  outline: 0;
  display: inline-block;
  padding: 8px;
  color: white;
  background-color: rgb(0, 180, 0);
  text-align: center;
  cursor: pointer;
  width: 100%;
  font-size: 18px;
}

.dwBtn:hover {
  opacity: 0;
}
<button class="dwBtn">Test</button>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-02
    • 1970-01-01
    • 1970-01-01
    • 2011-11-10
    • 1970-01-01
    相关资源
    最近更新 更多