gpt4 book ai didi

html - 制作简单的汉堡菜单

转载 作者:行者123 更新时间:2023-12-04 13:11:53 27 4
gpt4 key购买 nike

我正在学习如何为桌面和移动用户制作响应式导航栏的教程。我没有完全遵循,因为我必须更改我的 CSS,因为我有一个图像 Logo 。当我尝试制作汉堡菜单时,我无法在一列中看到所有导航链接。澄清一下,我想在右侧制作汉堡包线,并使其像应用程序一样运行。

/* Basic */

* {
margin: 0;
padding: 0;
box-sizing: border-box;
}

body {
font-family: 'Acme', sans-serif;
background: white;
line-height: 1.6;
}

ul {
list-style: none;
}

a {
text-decoration: none;
}


/* Navbar */

.navbar {
display: flex;
background: #004C66;
align-items: center;
justify-content: space-between;
width: 100%;
position: fixed;
padding: 0 30px;
}

.navbar .logo img {
width: 100%;
margin-top: 10px;
}

.navbar .nav-link {
padding: 10px 50px;
color: #333;
background-color: red;
}


/* Burger Navigation */

.burger {
display: none;
}

.burger div {
width: 25px;
height: 2px;
background-color: #333;
margin: 5px;
border-radius: 25%;
}

@media (max-width: 813px) {
.nav-link {
position: absolute;
padding: none;
right: 0px;
height: 92vh;
top: 8vh;
display: flex;
flex-direction: column;
align-items: center;
width: 50%;
}
}
<body>
<header class="navbar">
<a href="" class="logo"><img src="/img/logoS.png" alt=""></a>

<nav>
<ul>
<a class="nav-link" href="#">Home</a>
<a class="nav-link" href="#">Services</a>
<a class="nav-link" href="#">Contact</a>
</ul>
</nav>

<div class="burger">
<div class="line1"></div>
<div class="line2"></div>
<div class="line3"></div>
</div>

</header>

</body>

最佳答案

我已经对您的代码进行了一些更新。试试这个。

<style type="text/css">
/* Basic */

* {
margin: 0;
padding: 0;
box-sizing: border-box;
}

body {
font-family: 'Acme', sans-serif;
background: white;
line-height: 1.6;
}

ul {
list-style: none;
}

a {
text-decoration: none;
}


/* Navbar */

.navbar {
display: flex;
background: #004C66;
align-items: center;
justify-content: space-between;
width: 100%;
height: 70px;
position: fixed;
padding: 0 30px;
}

.navbar .logo img {
width: 100%;
margin-top: 10px;
}

nav{
margin-left: auto;
}

.navbar .nav-link {
padding: 10px 50px;
color: #333;
background-color: red;
color: white;
}


/* Burger Navigation */

.burger {
display: none;
}

.burgerContainer{
cursor: pointer;
display: flex;
align-items: center;
}
.burger div {
width: 25px;
height: 2px;
background-color: #fff;
margin: 5px;
border-radius: 25%;
}

@media (max-width: 1200px) {
nav {
position: fixed;
padding: 20px;
right: -100%; /* Hiding the Nav */
height: calc(100% - 70px); /* Minus header height */
top: 70px;
display: flex;
flex-direction: column;
align-items: center;
width: 270px;
background: #fff;
border-left: solid 1px #ddd;
transition: all 0.4s ease;
}
nav.showNav{
right: 0;
}
nav ul{
width: 100%;
}
.navbar .nav-link{
width: 100%;
display: block;
margin: 5px 0;
text-align: center;
}
.burger{
display: inline-block;
}
}
</style>


<header class="navbar">
<a href="" class="logo">
</a>
<nav>
<ul>
<a class="nav-link" href="#">Home</a>
<a class="nav-link" href="#">Services</a>
<a class="nav-link" href="#">Contact</a>
</ul>
</nav>
<div class='burgerContainer'>
<div class="burger">
<div class="line1"></div>
<div class="line2"></div>
<div class="line3"></div>
</div>
</div>
</header>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script>
$(".burgerContainer").on("click", function () {
$("nav").toggleClass("showNav");
});
</script>

关于html - 制作简单的汉堡菜单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64264356/

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