我只是在學習編碼,并希望理解和重新創建這個:https : //www.w3schools.com/howto/tryit.asp?filename=tryhow_js_topnav。
編輯:
我希望它在不使用 FontAwesome 的樣式表的情況下作業。
問題是當我在這里運行代碼片段時它可以作業,但不能在我的計算機上運行。它會丟失格式并執行以下操作:picture。有誰知道我做錯了什么?
function myFunction() {
var x = document.getElementById("myTopnav");
if (x.className === "topnav") {
x.className = " responsive";
} else {
x.className = "topnav";
}
}
body {
margin: 0;
font-family: ;
width: ;
padding: ;
}
.topnav {
overflow: hidden;
background-color: yellow;
}
.topnav a {
float: left;
display: block;
color: red;
text-align: ;
padding: 14px;
text-decoration: none;
font-size: ;
}
.topnav a:hover {
background-color: orange;
color: white;
}
.topnav a.active {
background-color: turquoise;
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 .icon {
position: absolute;
right: 0;
top: 0;
}
.topnav.responsive a {
float: none;
display: block;
text-align: left;
}
}
<!DOCTYPE html>
<html lang="nb">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel='stylesheet' href="./css/style.css">
</head>
<header>
</header>
<body>
<div class="topnav" id="myTopnav">
<a href="index.html" class="active">Hjem</a>
<a href="tjenester.html">Tjenester</a>
<a href="kontakt.html">Kontakt</a>
<a href="om-oss.html">Om oss</a>
<a href="javascript:void(0);" class="icon" onclick="myFunction()">☰</a>
</div>
<div>
<h2>Welcome</h2>
<p>Hi</p>
</div>
<script src="./js/javascript.js"></script>
</body>
</html>
有人還可以確切地解釋一下這是做什么的:
<a href="javascript:void(0);" class="icon" onclick="myFunction()"> <i class="fa fa-bars"></i></a>
uj5u.com熱心網友回復:
我認為您缺少 FontAwesome。嘗試將此添加到您的標題
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/378793.html
標籤:javascript html css
上一篇:使2 文本區域相互反射
