HTML 链接无法点击

标签 html css

由于某种原因无法点击我网站上“导航栏”上的链接,我似乎找不到原因。它在视口(viewport)中(这是网站的链接:https://codetheworld.000webhostapp.com/。网站上的链接应该是“学习编码”按钮)。一件有趣的事情是,一旦我打开检查元素窗口,它就会起作用。这是导航栏的代码片段:

#first {
  margin-top: 500px;
}

ul {
  list-style-type: none;
  margin: 0;
  padding: 0;
  position: relative;
  top: -1150px;
  left: 100px;
  z-index: 4;
}

li a {
  width: 200px;
  height: 50px;
  font-size: 2em;
  text-decoration: none;
  color: white;
  font-family: Georgia, serif;
  padding: 10px;
  border: 2px solid white;
  border-radius: 7px;
  text-align: center;
  line-height: 30px;
}

li a:hover {
  background-color: grey;
  color: white;
  text-decoration: none;
}
<ul id="first">
  <li><a href="tutorial.html">Learn to code</a></li>
</ul>

最佳答案

您将元素放置在视口(viewport)之外,因此无法点击它。 删除 margin-top 和 top 定位,一切都会起作用:

#first {
    background: black;
}

ul {
  list-style-type: none;
  margin: 0;
  padding: 0;
  position: relative;
  left: 100px;
  z-index: 4;
}

li a {
  width: 200px;
  height: 50px;
  font-size: 2em;
  text-decoration: none;
  color: white;
  font-family: Georgia, serif;
  padding: 10px;
  border: 2px solid white;
  border-radius: 7px;
  text-align: center;
  line-height: 30px;
}

li a:hover {
  background-color: grey;
  color: white;
  text-decoration: none;
}
<ul id="first">
  <li><a href="tutorial.html">Learn to code</a></li>
</ul>

关于HTML 链接无法点击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44090016/

相关文章:

php - 从数据库中获取同一页面中的结果

css - 如何在具有可变空间的 div 中包含一个 float

html - 在不影响 DOM 的情况下更改 div 大小

css - gulp-autoprefixer 中的级联选项

javascript - HTML/CSS/Javascript - 对齐表格中的文本

html - 位置 <表格 :radiobuttons> vertically

html - 当浏览器变小时,阻止左右链接相互渗透

html - 如何在 Angular2 中提供图像?

javascript - 如何修复导致 IE 8 故障的自定义 Kendo UI 主题 CSS?

html - Div 容器不按顺序