gpt4 book ai didi

html - 为什么我不能点击我网站上的导航栏元素?

转载 作者:可可西里 更新时间:2023-11-01 12:57:05 25 4
gpt4 key购买 nike

我的光标不会变成手形光标,而是变成文本光标。当我将鼠标悬停在导航栏中的每个元素上时,过渡动画不会播放。我只分配了一个链接到导航的“主页”,以查看它是否将我带到该链接。我使用 google.com 作为导航栏中“主页”的链接。

body {
margin: 0;
background: #222;
font-family: 'Work Sans', sans-serif;
font-weight: 400;
}

.container {
width: 80%;
margin: 0 auto;
}

header {
background: #247DAA;
}

header::after {
content: '';
display: table;
clear: both;
}

.logo {
float: left;
padding: 10px 0;
}

nav {
float: right;
}

nav ul {
margin: 0;
padding: 0;
list-style: none;
}

nav li {
display: inline-block;
margin-left: 70px;
padding-top: 23px;

position: relative;
}

nav a {
color: #444;
text-decoration: none;
font-size: 14px;
}

nav a:hover {
color: #000;
}

nav a::before {
content: '';
display: block;
height: 5px;
background-color: #444;

position: absolute;
top: 0;
width: 0%;

transition: all ease-in-out 250ms;
}

nav a:hover::before {
width: 100%;
}
<!DOCTYPE html>
<html>
<head>
<link href="https://fonts.googleapis.com/css?family=Work+Sans" rel="stylesheet">
<link href="styles.css" rel="stylesheet" type="text/css">
<meta charset="UTF-8">
<title>Website</title>
</head>
<body>
<header>
<div class="container">

<h1 class="logo"></h1>

<nav>
<ul>
<li><a href="https://www.google.com"></a>Home</li>
<li><a href="#"></a>About</li>
<li><a href="#"></a>News</li>
<li><a href="#"></a>Gallery</li>
<li><a href="#"></a>Contact</li>
</ul>
</nav>

</div>
</header>

</body>
</html>

最佳答案

您的菜单文本在 li 内标记,因此当您尝试单击菜单时,您单击的是 li不在你的<a> ( anchor )标签。

解决方案

只需将您的文字放入 <a> ( anchor )标签

例如:- <a href="">Your text should be here</a>

body {
margin: 0;
background: #222;
font-family: 'Work Sans', sans-serif;
font-weight: 400;
}

.container {
width: 80%;
margin: 0 auto;
}

header {
background: #247DAA;
}

header::after {
content: '';
display: table;
clear: both;
}

.logo {
float: left;
padding: 10px 0;
}

nav {
float: right;
}

nav ul {
margin: 0;
padding: 0;
list-style: none;
}

nav li {
display: inline-block;
margin-left: 70px;
padding-top: 23px;

position: relative;
}

nav a {
color: #444;
text-decoration: none;
font-size: 14px;
}

nav a:hover {
color: #000;
}

nav a::before {
content: '';
display: block;
height: 5px;
background-color: #444;

position: absolute;
top: 0;
width: 0%;

transition: all ease-in-out 250ms;
}

nav a:hover::before {
width: 100%;
}
<!DOCTYPE html>
<html>
<head>
<link href="https://fonts.googleapis.com/css?family=Work+Sans" rel="stylesheet">
<link href="styles.css" rel="stylesheet" type="text/css">
<meta charset="UTF-8">
<title>Website</title>
</head>
<body>
<header>
<div class="container">

<h1 class="logo"></h1>

<nav>
<ul>
<li><a href="https://www.google.com">Home</a></li>
<li><a href="#">About</a></li>
<li><a href="#">News</a></li>
<li><a href="#">Gallery</a></li>
<li><a href="#">Contact</a></li>
</ul>
</nav>

</div>
</header>

</body>
</html>

其他解决方案:

使用 CSS cursor:pointer你们想在没有 <a> 的元素上实现标签

关于html - 为什么我不能点击我网站上的导航栏元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48733532/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com