如何在汉堡菜单中加入链接?
How to incorporate links inside a hamburger menu?
我很难理解如何重新安排我的 HTML/CSS 代码以便在汉堡包导航菜单中移动一些链接。
我希望 'home' 始终可见,但是我希望其他链接页面位于汉堡菜单中,仅在单击菜单时可见...
我希望汉堡菜单中包含以下内容:
关于
接触
作品集等
关于如何实现这一点有什么建议吗?
* {
text-decoration: none;
}
body {
background-color: #f3f3f3;
}
header {
background-color: #fff;
width: 100%;
height: 100px;
display: table-cell;
}
.header-logo img {
height:100px;
padding: 10px 0px 10px 10px;
float: left;
}
header nav ul {
display: block;
margin: 0 auto;
width: fit-content;
padding-top: 30px;
}
header nav ul li {
display: inline-block;
padding: 0 5px;
}
header nav ul li a {
font-family:'Sorts Mill Goudy', serif;
font-size: 16px;
color: #111;
text-transform: uppercase;
}
.sub {
display: none;
background-color: rgb(70, 149, 223);
margin-left: 5%;
height: auto;
}
/* HAMBURGER MENU */
.nav div {
height: 4px;
background-color: rgb(20, 15, 15);
margin: 5px 0;
border-radius: 25px;
transition: 0.3s;
}
.nav {
width: 30;
display: block;
float: right;
margin: 1em 0 0 1em;
padding-right: 10px;
}
.one {
width: 30px;
}
.two {
width: 20px;
}
.three {
width: 25px;
}
.nav:hover div{
width: 30px;
}
ul li a:hover {
color: rgb(255, 255, 255);
}
<header>
<div class="header-logo">
<a href="index.html"> <img src="img/Milestonehackers.jpg" alt="Milestonehackers logo"></a>
</div>
<nav>
<ul> <li><a href="index.html">Home</a></li></ul>
<ul>
<a href="#" class="nav">
<div class="one"></div>
<div class="two"></div>
<div class="three"></div>
<li><a href="podcasts.html">Podcast</a></li>
<li><a href="newsletter.html">Newsletter</a></li>
<li><a href="blog.html">Blog</a></li>
<li><a href="contact.html">Contact</a></li>
<div class="sub">
<li><a href="subscribe.html">Subscribe</a></li>
</div>
</a>
</ul>
</nav>
</header>
您要查找的内容称为 toggle. For this you need to use javascript or jquery(简化的 javascript "version")。为了便于解释这一点,例如为要切换的子元素放置一个父元素 div。然后在你的 css 中显示这个父 div none。然后你使用 jquery 来告诉你想要点击什么,然后你想要切换什么。
//Script.js
$(document).ready(function(){ //Use ready to make a function available after the document is loaded
$(".nav").click(function(){
$("#hamburger").toggle(250);
});
});
/* Style.css */
* {
text-decoration: none;
}
body {
background-color: #f3f3f3;
}
header {
background-color: #fff;
width: 100%;
height: 100px;
display: table-cell;
}
.header-logo img {
height:100px;
padding: 10px 0px 10px 10px;
float: left;
}
header nav ul {
display: block;
margin: 0 auto;
width: fit-content;
padding-top: 30px;
}
header nav ul li {
display: inline-block;
padding: 0 5px;
}
header nav ul li a {
font-family:'Sorts Mill Goudy', serif;
font-size: 16px;
color: #111;
text-transform: uppercase;
}
.sub {
display: none;
background-color: rgb(70, 149, 223);
margin-left: 5%;
height: auto;
}
/* HAMBURGER MENU */
.nav div {
height: 4px;
background-color: rgb(20, 15, 15);
margin: 5px 0;
border-radius: 25px;
transition: 0.3s;
}
.nav {
width: 30;
display: block;
float: right;
margin: 1em 0 0 1em;
padding-right: 10px;
}
.one {
width: 30px;
}
.two {
width: 20px;
}
.three {
width: 25px;
}
.nav:hover div{
width: 30px;
}
#hamburger{
display:none;
}
ul li a:hover {
color: rgb(255, 255, 255);
}
<head>
<link rel="stylesheet" type="text/css" href="style.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script type = "text/javascript" src = "script.js">
</head>
<header>
<div class="header-logo">
<a href="index.html"> <img src="https://milestonehackers.com/img/Milestonehackers.jpg" alt="Milestonehackers logo"></a>
</div>
<nav>
<ul> <li><a href="index.html">Home</a></li></ul>
<ul>
<a href="#" class="nav">
<div class="one"></div>
<div class="two"></div>
<div class="three"></div>
<div id = "hamburger">
<li><a href="podcasts.html">Podcast</a></li>
<li><a href="newsletter.html">Newsletter</a></li>
<li><a href="blog.html">Blog</a></li>
<li><a href="contact.html">Contact</a></li>
</div>
<div class="sub">
<li><a href="subscribe.html">Subscribe</a></li>
</div>
</a>
</ul>
</nav>
</header>
编辑:我将 src 添加到新的 script.js 文件中,该文件应该包含您的点击功能:)
不要以为只使用 CSS 就可以实现你想要的,也许需要很多 CSS "hacks"。我建议添加一些 javascript 以在点击时显示。
我建议查看此页面 https://www.w3schools.com/howto/howto_js_mobile_navbar.asp,因为他们有一个示例,就像您要实现的示例一样。
我很难理解如何重新安排我的 HTML/CSS 代码以便在汉堡包导航菜单中移动一些链接。
我希望 'home' 始终可见,但是我希望其他链接页面位于汉堡菜单中,仅在单击菜单时可见...
我希望汉堡菜单中包含以下内容:
关于 接触 作品集等
关于如何实现这一点有什么建议吗?
* {
text-decoration: none;
}
body {
background-color: #f3f3f3;
}
header {
background-color: #fff;
width: 100%;
height: 100px;
display: table-cell;
}
.header-logo img {
height:100px;
padding: 10px 0px 10px 10px;
float: left;
}
header nav ul {
display: block;
margin: 0 auto;
width: fit-content;
padding-top: 30px;
}
header nav ul li {
display: inline-block;
padding: 0 5px;
}
header nav ul li a {
font-family:'Sorts Mill Goudy', serif;
font-size: 16px;
color: #111;
text-transform: uppercase;
}
.sub {
display: none;
background-color: rgb(70, 149, 223);
margin-left: 5%;
height: auto;
}
/* HAMBURGER MENU */
.nav div {
height: 4px;
background-color: rgb(20, 15, 15);
margin: 5px 0;
border-radius: 25px;
transition: 0.3s;
}
.nav {
width: 30;
display: block;
float: right;
margin: 1em 0 0 1em;
padding-right: 10px;
}
.one {
width: 30px;
}
.two {
width: 20px;
}
.three {
width: 25px;
}
.nav:hover div{
width: 30px;
}
ul li a:hover {
color: rgb(255, 255, 255);
}
<header>
<div class="header-logo">
<a href="index.html"> <img src="img/Milestonehackers.jpg" alt="Milestonehackers logo"></a>
</div>
<nav>
<ul> <li><a href="index.html">Home</a></li></ul>
<ul>
<a href="#" class="nav">
<div class="one"></div>
<div class="two"></div>
<div class="three"></div>
<li><a href="podcasts.html">Podcast</a></li>
<li><a href="newsletter.html">Newsletter</a></li>
<li><a href="blog.html">Blog</a></li>
<li><a href="contact.html">Contact</a></li>
<div class="sub">
<li><a href="subscribe.html">Subscribe</a></li>
</div>
</a>
</ul>
</nav>
</header>
您要查找的内容称为 toggle. For this you need to use javascript or jquery(简化的 javascript "version")。为了便于解释这一点,例如为要切换的子元素放置一个父元素 div。然后在你的 css 中显示这个父 div none。然后你使用 jquery 来告诉你想要点击什么,然后你想要切换什么。
//Script.js
$(document).ready(function(){ //Use ready to make a function available after the document is loaded
$(".nav").click(function(){
$("#hamburger").toggle(250);
});
});
/* Style.css */
* {
text-decoration: none;
}
body {
background-color: #f3f3f3;
}
header {
background-color: #fff;
width: 100%;
height: 100px;
display: table-cell;
}
.header-logo img {
height:100px;
padding: 10px 0px 10px 10px;
float: left;
}
header nav ul {
display: block;
margin: 0 auto;
width: fit-content;
padding-top: 30px;
}
header nav ul li {
display: inline-block;
padding: 0 5px;
}
header nav ul li a {
font-family:'Sorts Mill Goudy', serif;
font-size: 16px;
color: #111;
text-transform: uppercase;
}
.sub {
display: none;
background-color: rgb(70, 149, 223);
margin-left: 5%;
height: auto;
}
/* HAMBURGER MENU */
.nav div {
height: 4px;
background-color: rgb(20, 15, 15);
margin: 5px 0;
border-radius: 25px;
transition: 0.3s;
}
.nav {
width: 30;
display: block;
float: right;
margin: 1em 0 0 1em;
padding-right: 10px;
}
.one {
width: 30px;
}
.two {
width: 20px;
}
.three {
width: 25px;
}
.nav:hover div{
width: 30px;
}
#hamburger{
display:none;
}
ul li a:hover {
color: rgb(255, 255, 255);
}
<head>
<link rel="stylesheet" type="text/css" href="style.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script type = "text/javascript" src = "script.js">
</head>
<header>
<div class="header-logo">
<a href="index.html"> <img src="https://milestonehackers.com/img/Milestonehackers.jpg" alt="Milestonehackers logo"></a>
</div>
<nav>
<ul> <li><a href="index.html">Home</a></li></ul>
<ul>
<a href="#" class="nav">
<div class="one"></div>
<div class="two"></div>
<div class="three"></div>
<div id = "hamburger">
<li><a href="podcasts.html">Podcast</a></li>
<li><a href="newsletter.html">Newsletter</a></li>
<li><a href="blog.html">Blog</a></li>
<li><a href="contact.html">Contact</a></li>
</div>
<div class="sub">
<li><a href="subscribe.html">Subscribe</a></li>
</div>
</a>
</ul>
</nav>
</header>
编辑:我将 src 添加到新的 script.js 文件中,该文件应该包含您的点击功能:)
不要以为只使用 CSS 就可以实现你想要的,也许需要很多 CSS "hacks"。我建议添加一些 javascript 以在点击时显示。
我建议查看此页面 https://www.w3schools.com/howto/howto_js_mobile_navbar.asp,因为他们有一个示例,就像您要实现的示例一样。