html - 在按钮中悬停时切换图像

标签 html css twitter-bootstrap

我正在尝试更改悬停时放置在按钮中的图像。到目前为止,我已经设法让图像本身在您将鼠标悬停在图像上时发生变化,但在按钮本身悬停时不会发生变化。这是代码。

    <style>
    .btn-large{
        width: 300px;
        height: 350px;
    }
    .movie{
        width: 90px;
        height: 90px;
        position: relative;
        margin-top: 25px;
    }
    #hardware:hover, #hardware:active{
        background: #23c6c8;
        color: white;
    }
    </style>

    <a href="#" class="btn btn-large" id="hardware">
            <figure>
                <img class="movie" alt="ticket" src="http://i.imgur.com/u8wsfFL.png" onmouseover="this.src='http://i.imgur.com/BuK26gd.png'" onmouseout="this.src='http://i.imgur.com/u8wsfFL.png'" />
            </figure>
                <div class="details">
                    <h2>All Tickets</h2></br>
                    <p>View all tickets</p>
                </div>
            </a>

最佳答案

您需要将事件处理程序移动到 anchor 而不是 img 并搜索 img 标签

Demo

<a href="#" class="btn btn-large" id="hardware"
   onmouseover="this.getElementsByTagName('img')[0].src ='http://i.imgur.com/BuK26gd.png'" 
   onmouseout="this.getElementsByTagName('img')[0].src = 'http://i.imgur.com/u8wsfFL.png'">
  <figure>
    <img class="movie" alt="ticket" src="http://i.imgur.com/u8wsfFL.png"  />
  </figure>
  <div class="details">
    <h2>All Tickets</h2></br>
    <p>View all tickets</p>
  </div>
</a>

关于html - 在按钮中悬停时切换图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31598614/

相关文章:

javascript - 如何更改 anchor 标记的属性值

html - Bootstrap 4 中如何使卡头无边框半径?

css - Bootstrap 中汉堡菜单项的背景

html - 右对齐列表项中的一些文本

javascript - 它没有记录我悬停在一个元素上

c# - 在c#中将html转换为json

css - 仅使用 css 在 div 中插入三 Angular 形

css - 显示:inline-block in <p> and <div>

javascript - 如何选择带有列表项的偶数行

jquery - 限制 Bootstrap 工具提示在所有页面上触发