【问题标题】:Making a DIV work with hover and as a link使用悬停和链接使 DIV 工作
【发布时间】:2018-02-08 06:16:43
【问题描述】:

我正在尝试制作一个 div,它会在您悬停时改变行为(反转背景和徽标的颜色)并且也是一个链接。

我已经设法让这两种行为(作为链接和反转颜色)正常工作,但只能独立工作 - 我无法让两者一起工作。

我怀疑是因为创建链接的 span 标签,但不能确定:

.full_box a span {
position: absolute;
width: 100%;
height: 100%;
top: 0;
left: 0;
z-index: 1
}

你可以在这里看到我的代码:https://jsfiddle.net/omcoombs/4pbpto2z/

提前致谢

【问题讨论】:

  • 我应该说 - 我已经注释掉了分析 div 中的链接,你可以看看你是否取消注释它是因为悬停不能正常工作。

标签: html css hyperlink hover


【解决方案1】:

如果您将div inside 添加到a 元素,它将起作用。示例:

.big-box {  
  background: cyan;
  border: 1px solid black;
  height: 200px;
  width: 100px;
}

.big-box a {
  border: none;
  margin: 0;
  padding: 0;
}

.small-box {
  background: white;
  height: 100px;
  width: 100%;
}

.small-box:hover {
  background: red;
}
<div class="big-box">
  <a href="about:blank">
    <div class="small-box">
      logo or sg
    </div>
  </a>
</div>

【讨论】:

  • 好的,谢谢 - 我会试一试,虽然我实际上也设法修复了它!
  • 总是这样,我会花几个小时在上面胡思乱想,然后我一提出问题,我就会解决它。还是谢谢。
猜你喜欢
  • 1970-01-01
  • 2017-11-24
  • 1970-01-01
  • 1970-01-01
  • 2013-01-13
  • 1970-01-01
  • 2015-05-31
  • 2021-05-08
  • 2015-03-03
相关资源
最近更新 更多