汉堡菜单图标应位于右侧,图像应位于左侧站点。
当我们单击菜单打开时,它应该打开一个下拉菜单,里面应该是徽标主页关于我们画廊联系方式。
<div class="rectangle1">
<ul class="dropdown">
<li class="li1"><a href="home.html"><img class="img" src="YOGI Logo.svg" alt=""> </a></li>
<li class="li2"><a class="a1" href="#home">Home</a></li>
<li class="li3"><a class="a2" href="aboutus.html">About Us</a></li>
<li class="li4"><a class="a3" href="gallery.html">Gallery</a></li>
<li class="li5"><a class="a4" href="contact.html">Contact</a></li>
<a class="Contact_Us" href="contact.html">
<img class="Contact-us-img"src="Vector.svg" alt="">
<span class="Contact-us-text">Contact Us</span>
</a>
</ul>
</div>
我只需要把它转成CSS即可。
我需要它让 iPhone 14 Pro 能够响应汉堡菜单。
我认为这可能对您有帮助:CSS @media Rule。正如您在该教程中看到的,CSS 中有一种方法可以检查屏幕的宽度。
@media only screen and (max-width: 600px) {
body {
background-color: lightblue;
}
}
在此示例中,当宽度小于 600 像素时,背景颜色将设置为浅蓝色。使用此规则,您可以相应地更改 CSS。
你绝对应该尝试自己实现它,而不仅仅是从互联网上复制粘贴。去尝试,享受 CSS 的乐趣;这是学习它的唯一方法。
这里是修改后的 CSS 代码,用于实现响应式汉堡菜单:
CSS(样式.css):
body {
margin: 0;
font-family: Arial, sans-serif;
}
header {
background-color: #333;
color: #fff;
padding: 10px;
display: flex;
align-items: center;
}
.container {
display: flex;
justify-content: space-between;
align-items: center;
}
.logo {
color: #fff;
text-decoration: none;
font-size: 24px;
}
.menu-toggle {
width: 30px;
height: 30px;
background-color: #fff;
cursor: pointer;
display: none; /* Hide the menu icon by default on larger screens */
}
.menu-toggle::before, .menu-toggle::after {
content: "";
display: block;
width: 100%;
height: 3px;
background-color: #333;
}
.menu {
display: flex;
align-items: center;
}
.menu ul {
list-style: none;
margin: 0;
padding: 0;
display: flex;
}
.menu li {
padding: 10px;
}
.menu a {
color: #fff;
text-decoration: none;
font-size: 18px;
}
/* Media Query for Mobile Devices */
@media only screen and (max-width: 767px) {
.menu {
display: none; /* Hide the menu by default on small screens */
flex-direction: column;
background-color: #333;
position: absolute;
top: 50px;
right: 0;
width: 100%;
}
.menu.active {
display: flex; /* Show the menu when active */
}
.menu li {
width: 100%;
text-align: center;
}
.menu-toggle {
display: block; /* Show the menu icon on small screens */
}
}