html - 在不使用额外的 div 的情况下在悬停时更改图像

标签 html css

我试图让我的页脚 img 在悬停时更改为不同的 img,我已经通过创建每个 img 来完成此操作作为 div,但是,我试图避免这种情况,还有其他可能的方法吗?

当前的 CSS:

.footerLeft {
  float:left;
  width: 50%;
  height: 100px;
  color: #fff;
  background-color: #33383b;
}
.footerLeft p {
  margin-left: 25px;
}
.footerLeft img {
  width: 175px;
  height: 50px;
  padding-left: 25px;
  margin-top: 10px;
}
.footerRight {
  float:right;
  width: 50%;
  height: 100px;
  color: #fff;
  background-color: #33383b;
}
.footerRight img {
  width: 35px;
  height: 35px;
}
.footerRight p {
  text-align: right;
  position:relative;
  margin-top: -20px;
  margin-right: 20px;
}

当前的 HTML:

<div class="footerLeft">
<img src="img/logo.png">
<p>Sharpturn Network&copy; 2016</p>
</div>
<div class="footerRight">
<ul id="menu">
  <li><a href="https://www.facebook.com/SharpturnNetwork" target="_blank"><img src="img/footer/facebook.png"></a></li>
  <li><a href="https://www.twitter.com/SharpturnNet" target="_blank"><img src="img/footer/twitter.png"></a></li>
  <li><a href="https://www.youtube.com/sharpturnnetwork" target="_blank"><img src="img/footer/youtube.png"></a></li>
</ul>
<p>Designed by Ryan Williams</p>
</div>

最佳答案

将一个 img 设置为背景 img,将另一个设置为悬停时的背景图像。

footer {
  background-image: url(...);
}
footer:hover {
  background-image: url(...);
}

关于html - 在不使用额外的 div 的情况下在悬停时更改图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35531530/

相关文章:

html - IE7中CSS下拉定位问题

JQuery 样式显示值

html - 在可以更改尺寸的容器内水平居中 div

positioning - CSS溢出定位

html - 如何正确缩进无序列表?左边距不起作用!

javascript - HTML 文本区域选项卡支持

html - 如何让我的 flexbox 导航栏固定在屏幕顶部?

CSS3 变换 : perspective doesn't want to work in Opera < 21

jquery - jquery 和 quicksand 的 CSS <li> 问题

javascript - 在 PHP 函数中运行 Jquery