【问题标题】:How can I fix an image link that's not working?如何修复不起作用的图像链接?
【发布时间】:2019-05-07 07:41:02
【问题描述】:

我正在尝试为我的页面导航栏获取图片以链接回我网站的主页。我尝试使用下面的代码,但由于某种原因,只有图像的顶部是可点击的。我已经检查过它并尝试了很长时间,但我找不到任何看起来不合适或语法不正确的东西。

有什么办法可以解决这个问题吗?

nav {
  height: 85px;
  position: fixed;
  top: 0px;
  left: 0px;
  width: 100%;
  background: none;
  padding-left: 60px;
  padding-right: 60px;
  user-select: none;
  transition: 0.5s ease-in-out;
  z-index: 100;
}

nav img {
  height: 70px;
  margin-top: 5px;
}

nav a:hover {
  color: var(--primary) !important;
  transition: 0.15s;
}

nav img {
  margin: 0px;
}

nav .responsive-nav {
  display: none;
}

nav .right {
  position: fixed;
  top: 27px;
  right: 60px;
  width: 100%;
  text-align: right;
  height: 85px;
  text-transform: uppercase;
}

nav .right ul {
  position: fixed;
  top: 27px;
  right: 60px;
  width: 100%;
  height: 85px;
  margin-top: 0px;
}

nav .right li {
  margin-top: 7px;
}

nav .right a {
  text-decoration: none;
  color: #ffffff;
  font-size: 16px;
  margin-left: 20px;
}

nav h1 a {
  text-decoration: none;
  color: #ffffff;
  transition: 0.15s;
}

nav h1 a:hover {
  color: var(--primary);
  transition: 0.15s;
}

nav .menu {
  display: none;
  position: fixed;
  top: 18px;
  right: 30px;
  font-size: 25px;
  border: 2px solid var(--primary);
  border-radius: 5px;
  padding: 5px;
  color: var(--primary);
  cursor: pointer;
}
<nav>
    <a href="/"><img src="https://www.gsr-technology.co.uk/wp-content/uploads/2015/10/partner-logo-placeholder.jpg" /></a>
    <div class="right">
      <ul>
        <li><a href="/">Home</a></li>
        <li><a href="/services.html">Services</a></li>
      </ul>
    </div>
    <i class="fas fa-bars menu"></i>
  </nav>

【问题讨论】:

  • 你为什么使用 position:fixed ? .right div 与徽标重叠(添加背景颜色以更好地查看问题)
  • 当您检查标记时,您的浏览器开发工具会显示什么?

标签: html css image hyperlink


【解决方案1】:

在上面的代码中nav .rightnav .right ul 都有宽度:100%;删除它并尝试它会完成,整个图像将是可点击的。

【讨论】:

  • 您能提出其他解决方案吗?
  • @B.Sommer 此解决方案解决了您发布的代码的问题。如果您仍然遇到问题,那么您需要使用您实际拥有的所有代码更新问题。但是,更好的解决方案是让您推断此修复需要什么,然后将其应用到您的实际场景中,只要存在代码冲突(例如)重叠。
  • 我尝试删除两行 'width: 100%;' in. 这是正确的吗?
  • 我意识到我的错误:我已经更改了我的 css 文件中的样式,但后来在媒体查询中的规则被覆盖了。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-01-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-22
相关资源
最近更新 更多