【问题标题】:Change button border on hover悬停时更改按钮边框
【发布时间】:2021-05-19 16:17:19
【问题描述】:

我无法让悬停在我的按钮上工作。我希望我的按钮没有边框,但是当我的鼠标在它上面时显示一个蓝色边框。当鼠标不在顶部但已排序时,我还需要它来更改图像,因此 changeImage 函数:)。只是需要边界方面的帮助,有什么建议吗?

HTML

<input type="button" class = "button" onclick="changeImage('https://www.trafalgar.com/real-word/wp-content/uploads/sites/3/2019/10/giant-panda-750x400.jpg')" onmouseover="changeImage('https://www.trafalgar.com/real-word/wp-content/uploads/sites/3/2019/10/giant-panda-750x400.jpg')" value="Panda"
/>

CSS

.button {
          margin-right: 20px;
          width:300px;
          height:300px;
          background-color: transparent;
          border:none;
  
  .button:hover {
        border:2px solid #0000ff;
        border-radius: 20px;
            }

【问题讨论】:

  • 你忘记了 } 的结尾 .button

标签: html css button hover border


【解决方案1】:

.button {
          margin-right: 20px;
          width:300px;
          height:300px;
          background-color: transparent;
          border:none;
  }
  .button:hover {
        border: 2px solid  blue;
        border-radius: 20px;
        cursor:pointer;
            }
<input type="button" class = "button"   value="Panda"
/>

【讨论】:

  • 我向上帝发誓我太愚蠢了,缺少一个右括号。谢谢
  • 发生在我们所有人身上!
【解决方案2】:

缺少右括号 }

.button {
  margin-right: 20px;
  width:300px;
  height:300px;
  background-color: transparent;
  border:none;
}
  
.button:hover {
  border:2px solid #0000ff;
  border-radius: 20px;
}
&lt;input type="button" class = "button" onclick="changeImage('https://www.trafalgar.com/real-word/wp-content/uploads/sites/3/2019/10/giant-panda-750x400.jpg')" onmouseover="changeImage('https://www.trafalgar.com/real-word/wp-content/uploads/sites/3/2019/10/giant-panda-750x400.jpg')" value="Panda" /&gt;

【讨论】:

    【解决方案3】:

    如果您将右括号添加到您的 css 规则 button,则会出现悬停边框。你只是错过了;-)

    关于图像的更改,我不确定我是否理解正确……但最后:没有 JS 代码就不能说太多了。如果您可以显示 JS 代码,这将是有帮助的 ;-)

    .button {
              margin-right: 20px;
              width:300px;
              height:300px;
              background-color: transparent;
              border:none;
    
    } /* <<< add missing bracket here */
      
      .button:hover {
            border:2px solid #0000ff;
            border-radius: 20px;
                }
    
    

    【讨论】:

    • 是的,解决了。图片改了我整理的,不用贴js了。谢谢你;)
    猜你喜欢
    • 2016-02-01
    • 1970-01-01
    • 2015-08-21
    • 1970-01-01
    • 1970-01-01
    • 2016-08-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多