gpt4 book ai didi

html - 安装了导航栏但不能链接html上的页面

转载 作者:行者123 更新时间:2023-11-28 00:08:29 25 4
gpt4 key购买 nike

我已经安装了一个导航栏,我已经为栏上的每个选项(主页、新闻、关于和联系人)创建了 HTML 文件,但只有地址栏发生了变化。我知道我必须添加一个 a) 标签,但我不确定我需要在哪里以及为什么需要更改我的代码。另外,我是否需要为每个 HTML 页面复制此代码?我的代码在我的索引下面

<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
body {
margin: 0;
font-family: Arial, Helvetica, sans-serif;
}

.topnav {
overflow: hidden;
background-color: #333;
}

.topnav a {
float: left;
color: #f2f2f2;
text-align: center;
padding: 14px 16px;
text-decoration: none;
font-size: 17px;
}

.topnav a:hover {
background-color: #ddd;
color: black;
}

.topnav a.active {
background-color: #4CAF50;
color: white;
}
</style>
</head>
<body>

<div class="topnav">
<a class="active" href="#home">Home</a>
<a href="#news">News</a>
<a href="#contact">Contact</a>
<a href="#about">About</a>
</div>

<div style="padding-left:16px">
<h2>Top Navigation Example</h2>
<p>Some content..</p>
</div>

</body>
</html>

最佳答案

您必须复制应在每个页面上显示的 HTML 部分。您的导航问题是您使用的是 <a>标签 href对于您想要实现的目标,属性不正确。我假设您必须将导航更改为类似这样的内容。

<div class="topnav">
<a class="active" href="index.html">Home</a>
<a href="news.html">News</a>
<a href="contact.html">Contact</a>
<a href="about.html">About</a>
</div>

基本上,你必须修改href=并在 = 之后添加您要链接到的 HTML 文件的相对路径。我建议阅读更多关于 link tags here 的内容和 href attribute here .如果你把 #预先在你的href您在当前页面中链接到 anchor 的属性(具有特定 id 的标签)。这也会更改地址栏中的 URL,但不会打开 HTML 文件。

关于html - 安装了导航栏但不能链接html上的页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55564855/

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