gpt4 book ai didi

html - 我的 fa fa-bars 没有显示 - 响应式顶部导航

转载 作者:太空宇宙 更新时间:2023-11-04 06:34:01 26 4
gpt4 key购买 nike

所以我在这里稍微改变一下我的装备。我为我的菜单创建了一个响应式导航栏,但不幸的是,当它处于移动形式时,它没有在菜单栏中显示标题。对于我的导航栏更新,我复制并粘贴了 W3schools 的代码,然后对其进行了一些修改。我打算稍后更改颜色。

现在,我遇到的唯一问题是当我进入响应模式时 fa fa-bars 没有显示。 这是为什么呢?这是我从中获得响应式导航栏的地方。 https://www.w3schools.com/howto/howto_js_topnav_responsive.asp .

告诉我我错过了什么。谢谢。 您可以运行下面的代码片段来了解我在说什么。

function myFunction() {
var x = document.getElementById("myTopnav");
if (x.className === "topnav") {
x.className += " responsive";
} else {
x.className = "topnav";
}
}
.topnav {
overflow: hidden;
background-color: #333;
}

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

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

.active {
background-color: #4CAF50;
color: white;
}

.topnav .icon {
display: none;
}

@media screen and (max-width: 600px) {
.topnav a:not(:first-child) {
display: none;
}
.topnav a.icon {
float: right;
display: block;
}
}

@media screen and (max-width: 600px) {
.topnav.responsive {
position: relative;
}
.topnav.responsive a.icon {
position: absolute;
right: 0;
top: 0;
}
.topnav.responsive a {
float: none;
display: block;
text-align: left;
}
}
<!DOCTYPE html>
<html>

<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Homepage</title>
<link rel="stylesheet" type="text/css" href="main.css">
<script src="script.js"></script>
</head>

<body>

<!-- The navigation menu -->

<div class="topnav" id="myTopnav">
<a href="#home" class="active">Home</a>
<a href="about.html">About Me</a>
<a href="portfolio.html">Portfolio</a>
<a href="contact.html">Contact</a>
<a href="javascript:void(0);" class="icon" onclick="myFunction()">
<i class="fa fa-bars"></i>
</a>
</div>

</body>

</html>

回复

function myFunction() {
var x = document.getElementById("myTopnav");
if (x.className === "topnav") {
x.className += " responsive";
} else {
x.className = "topnav";
}
}
.topnav {
overflow: hidden;
background-color: #333;
}

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

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

.active {
background-color: #4CAF50;
color: white;
}

.topnav .icon {
display: none;
}

@media screen and (max-width: 600px) {
.topnav a:not(:first-child) {
display: none;
}
.topnav a.icon {
float: right;
display: block;
}
}

@media screen and (max-width: 600px) {
.topnav.responsive {
position: relative;
}
.topnav.responsive a.icon {
position: absolute;
right: 0;
top: 0;
}
.topnav.responsive a {
float: none;
display: block;
text-align: left;
}
}


/* This is the part that messed up my styling for my home page which
which I previously was pleased with before. */

.summary {
min-height: 75vh;
max-width: 2000px;
display: flex;
align-items: center;
justify-content: center;
}

.profilePicture {
padding: 2rem;
}

.profileSummary {
max-width: 400px;
}
<!DOCTYPE html>
<html>

<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Homepage</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<link rel="stylesheet" type="text/css" href="main.css">
<script src="script.js"></script>
</head>

<body>

<div class="topnav" id="myTopnav">
<a href="#home" class="active">Home</a>
<a href="about.html">About Me</a>
<a href="portfolio.html">Portfolio</a>
<a href="contact.html">Contact</a>
<a href="javascript:void(0);" class="icon" onclick="myFunction()">
<i class="fa fa-bars"></i>
</a>
</div>



<span>
<div class="summary">
<div class="profilePicture">
<img src="https://ih1.redbubble.net/image.464384650.8618/flat,550x550,075,f.jpg" style="width: 170px; height: 170px; border-radius:50%;">
</div>
<div class="profileSummary">
Attentive alas because yikes due shameful ouch much kookaburra cantankerously up unbridled far vulnerably climbed aristocratically hired brusque fox said the therefore terrier scallop innocent on goodness mongoose woolly showed insistently
and.
</div>
</div>
</span>


</body>

</html>

最佳答案

你错过了 <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css"> .如果您使用的是 font-awesome,请不要忘记使用相关的 css。

function myFunction() {
var x = document.getElementById("myTopnav");
if (x.className === "topnav") {
x.className += " responsive";
} else {
x.className = "topnav";
}
}
.topnav {
overflow: hidden;
background-color: #333;
}

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

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

.active {
background-color: #4CAF50;
color: white;
}

.topnav .icon {
display: none;
}

@media screen and (max-width: 600px) {
.topnav a:not(:first-child) {
display: none;
}
.topnav a.icon {
float: right;
display: block;
}
}

@media screen and (max-width: 600px) {
.topnav.responsive {
position: relative;
}
.topnav.responsive a.icon {
position: absolute;
right: 0;
top: 0;
}
.topnav.responsive a {
float: none;
display: block;
text-align: left;
}
}
<!DOCTYPE html>
<html>

<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Homepage</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<link rel="stylesheet" type="text/css" href="main.css">
<script src="script.js"></script>
</head>

<body>

<!-- The navigation menu -->

<div class="topnav" id="myTopnav">
<a href="#home" class="active">Home</a>
<a href="about.html">About Me</a>
<a href="portfolio.html">Portfolio</a>
<a href="contact.html">Contact</a>
<a href="javascript:void(0);" class="icon" onclick="myFunction()">
<i class="fa fa-bars"></i>
</a>
</div>

</body>

</html>

关于html - 我的 fa fa-bars 没有显示 - 响应式顶部导航,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54394498/

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