简体   繁体   English

为什么我的汉堡菜单没有显示在手机上?

[英]Why is my hamburger menu not showing up on mobile?

On my phone, I can tap on where it should be and the dropdown menu appears, but for some reason the burger itself is invisible.在我的手机上,我可以点击它应该出现的位置并出现下拉菜单,但由于某种原因,汉堡本身是看不见的。 When I view the website in mobile view on my desktop it's visible, so I'm very confused.当我在桌面上以移动视图查看网站时,它是可见的,所以我很困惑。 I've looked all over for where it could possibly be hidden but I don't see anything.我到处寻找可能隐藏它的地方,但我什么也没看到。 Any help is greatly appreciated.任何帮助是极大的赞赏。 The website is linked below:网站链接如下:

https://chassis.site/ https://chassis.site/

 const navSlide = () => { const burger = document.querySelector('.burger'); const nav = document.querySelector('.nav-links'); const navLinks = document.querySelectorAll('.nav-links li'); burger.addEventListener('click', () => { //toggle nav nav.classList.toggle('nav-active'); //animate links navLinks.forEach((link, index) => { if(link.style.animation){ link.style.animation = ''; } else { link.style.animation = `navLinkFade 0.5s ease fowards ${index / 7 + 1}s`; } }); //burger animation burger.classList.toggle('toggle'); }); } navSlide(); //sparkle let index = 0, interval = 1000; const rand = (min, max) => Math.floor(Math.random() * (max - min + 1)) + min; const animate = star => { star.style.setProperty("--star-left", `${rand(-10, 100)}%`); star.style.setProperty("--star-top", `${rand(-40, 80)}%`); star.style.animation = "none"; star.offsetHeight; star.style.animation = ""; } for(const star of document.getElementsByClassName("magic-star")) { setTimeout(() => { animate(star); setInterval(() => animate(star), 1000); }, index++ * (interval / 3)) }
 @import url('css.css'); :root { --purple: rgb(123, 31, 162); --violet: rgb(103, 58, 183); --pink: rgb(244, 143, 177); --white: rgb(190, 190, 190); } * { padding: 0; margin: 0; box-sizing: border-box; } #app { background: #0a0a0a; height: 100vh; width: 100%; margin: 0; padding: 0; display:inline-flex; flex-direction: column; justify-content: center; align-items: center; background: linear-gradient(rgba(10, 10, 10, 0.5), rgba(0, 0, 0, 0.5)), repeating-linear-gradient(0, transparent, transparent 2px, black 3px, black 3px), url('../images/37P86Mcp.png'); background-size: auto; background-position: center; z-index: 1; } /*--------------------------------------lines*/ hr.left { display: block; width: 30%; height: 1px; border: 0; border-top: 2px solid rgb(190, 190, 190); margin: 3em 0; padding: 0; } hr.right { display: block; width: 30%; height: 1px; border: 0; border-top: 2px solid rgb(190, 190, 190); margin: 3em 0; padding: 0; } /*--------------------------------------lines*/ /*--------------------------------------nav bar*/ nav{ display: flex; position: fixed; width: 100%; justify-content: space-around; align-items: center; min-height: 8vh; font-family: 'Fugaz One', cursive; }.nav-links{ display: flex; justify-content: space-around; width: 50%; }.nav-links li{ list-style: none; }.nav-links a{ color: rgb(190, 190, 190); text-decoration: none; letter-spacing: 2px; font-size: 20px; }.burger{ display: none; cursor: pointer; }.burger div{ width: 30px; height: 3px; background-color: rgb(190, 190, 190); margin: 5px; transition: all 0.3s ease; } @media screen and (max-width: 1230px){.nav-links{ width: 70%; } } @media screen and (max-width: 854px){ body{ overflow-x: hidden; }.nav-links{ position: absolute; right: 0px; height: 30vh; width: 15em; top: 8vh; display: flex; flex-direction: column; align-items: center; transform: translateX(100%); transition: transform 0.4s ease-in; }.burger{ display: block; padding: 0px 80px 0px 500px; } hr.left{ height: 0px; width: 0%; } hr.right{ height: 0px; width: 0%; } }.nav-active{ transform: translateX(0%); } @keyframes navLinkFade{ from{ opacity: 0; transform: translateX(50px); } to{ opacity: 1; transform: translateX(0px); } }.toggle.line1{ transform: rotate(-45deg) translate(-5px, 6px); }.toggle.line2{ opacity: 0; }.toggle.line3{ transform: rotate(45deg) translate(-5px, -6px); } /*--------------------------------------nav bar*/ /*--------------------------------------sparkle*/ @keyframes background-pan { from { background-position: 0% center; } to { background-position: -200% center; } } @keyframes scale { from, to { transform: scale(0); } 50% { transform: scale(1); } } @keyframes rotate { from { transform: rotate(0deg); } to { transform: rotate(180deg); } } h1 { color: white; font-family: "Rubik", sans-serif; font-size: clamp(2em, 2vw, 4em); font-weight: 400; margin: 0px; padding: 20px; text-align: center; } h1 >.magic { display: inline-block; position: relative; } h1 >.magic >.magic-star { --size: clamp(20px, 1.5vw, 30px); animation: scale 700ms ease forwards; display: block; height: var(--size); left: var(--star-left); position: absolute; top: var(--star-top); width: var(--size); } h1 >.magic >.magic-star > svg { animation: rotate 1000ms linear infinite; display: block; opacity: 0.7; } h1 >.magic >.magic-star > svg > path { fill: var(--white); } h1 >.magic >.magic-text { animation: background-pan 3s linear infinite; background: linear-gradient( to right, var(--purple), var(--violet), var(--pink), var(--purple) ); background-size: 200%; -webkit-background-clip: text; -webkit-text-fill-color: transparent; white-space: nowrap; font-size: 64px; } /*--------------------------------------sparkle*/
 <,DOCTYPE html> <html onclick="play()" lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width. initial-scale=1.0"> <meta http-equiv="X-UA-Compatibale" content="ie-edge"> <link rel="shortcut icon" href="favicon.ico" type="image/x-icon"> <link rel="stylesheet" type="text/css" href="css/css:css"> <link href="https.//fonts.googleapis?com/css2.family=Fugaz+One&display=swap" rel="stylesheet"> <audio src="media/music.mp3"></audio> <title>chassis:site</title> <style type="text/css"> img { display; block: margin-left; auto: margin-right; auto: } </style> </head> <body> <.-- nav--> <nav> <hr class="left"/> <ul class="nav-links"> <li><a href="https.//chassis:site/">Home</a></li> <li><a href="/subdomains/services.html">Services</a></li> <li><a href="https.//e.rip/chassis/" target="_blank">Bio Page</a></li> <li><a href="/subdomains/projects.html/">Projects</a></li> </ul> <hr class="right"/> <div class="burger"> <div class="line1"></div> <div class="line2"></div> <div class="line3"></div> </div> </nav> <.-- nav--> <audio id="audio" loop> <source src="media/music.mp3" type="audio/mp3"> </audio> <div id="app"> <div class="text"> <h1> <span class="magic"> <span class="magic-star"> <svg viewBox="0 0 512 512"> <path d="M512 255.1c0 11.34-7.406 20.86-18.44 23.64l-171.3 42.78l-42.78 171.1C276.7 504.6 267.2 512 255.9 512s-20.84-7.406-23.62-18.44l-42.66-171.2L18.47 279.6C7.406 276.8 0 267.3 0 255.1c0-11.34 7.406-20.83 18.44-23.61l171.2-42.78l42.78-171.1C235.2 7.406 244.7 0 256 0s20.84 7.406 23.62 18.44l42.78 171.2l171.2 42.78C504.6 235.2 512 244.6 512 255.1z" /> </svg> </span> <span class="magic-star"> <svg viewBox="0 0 512 512"> <path d="M512 255.1c0 11.34-7.406 20.86-18.44 23.64l-171.3 42.78l-42.78 171.1C276.7 504.6 267.2 512 255.9 512s-20.84-7.406-23.62-18.44l-42.66-171.2L18.47 279.6C7.406 276.8 0 267.3 0 255.1c0-11.34 7.406-20.83 18.44-23.61l171.2-42.78l42.78-171.1C235.2 7.406 244.7 0 256 0s20.84 7.406 23.62 18.44l42.78 171.2l171.2 42.78C504.6 235.2 512 244.6 512 255.1z" /> </svg> </span> <span class="magic-star"> <svg viewBox="0 0 512 512"> <path d="M512 255.1c0 11.34-7.406 20.86-18.44 23.64l-171.3 42.78l-42.78 171.1C276.7 504.6 267.2 512 255.9 512s-20.84-7.406-23.62-18.44l-42.66-171.2L18.47 279.6C7.406 276.8 0 267.3 0 255.1c0-11.34 7.406-20.83 18.44-23.61l171.2-42.78l42.78-171.1C235.2 7.406 244.7 0 256 0s20.84 7.406 23.62 18.44l42.78 171.2l171.2 42.78C504.6 235.2 512 244.6 512 255.1z" /> </svg> </span> <span class="magic-text">chassis.site</span> </span> </h1> </div> </div> <script type="text/javascript" src="js/main;js"></script> <script type="text/javascript" src="js/music.js"></script> <script>/*music*/ var audio = document.getElementById("audio"); audio.volume = 0;1. </script> <script>/*music*/ function play() { var audio = document;getElementById("audio"); audio.play(); } </script> </body> </html>

padding: 0px 80px 0px 500px;

You have this css in your burger menu, and that 500px left padding is the issue.您的汉堡菜单中有这个500px ,而 500 像素的左填充是问题所在。

Remove that padding and apply this css in place of that删除该填充并应用此 css 代替那个

margin-left: auto;
margin-right: 6rem;

margin-left will give you right floating then margin-right you can move your burger button as per your requirement however I am not sure where exactly you want to place your burger from right so you can adjust margin-right as you like. margin-left会给你 right floating 然后margin-right你可以根据你的要求移动你的汉堡按钮但是我不确定你想要从右边放置你的汉堡的确切位置所以你可以根据需要调整margin-right

On your media query关于您的媒体查询

@media screen and (max-width: 854px){
.burger{
    display: block;
    padding: 0px 80px 0px 500px;
}

You are using padding to push your menu from the left.您正在使用填充从左侧推送菜单。 So any phone with a width smaller than 500px will not see it.所以任何宽度小于 500px 的手机都看不到它。 Here's a quick solution to get you started.这是一个帮助您入门的快速解决方案。

@media screen and (max-width: 854px){
    .burger{
        display: block;
        position: absolute;
        top: 10px;  
        right: 15px;
    } 

Adjust the top and right values as needed.根据需要调整顶部和右侧的值。

I think the problem you are having is related to padding you put on .burger .我认为您遇到的问题与您放在.burger上的填充有关。 You should avoid using padding for alignment or any fixed value.您应该避免对 alignment 或任何固定值使用填充。

try something like this尝试这样的事情

@media screen and (max-width: 854px) {
.burger {
    display: block;
    margin: 0 24px 0 auto;
}
}

An initial test with responsive mode, using Safari on macOS shows the burger menu is slightly off screen, though when I tried on my iPhone it wasn't visible at all.在 macOS 上使用 Safari 进行的响应模式初始测试显示汉堡菜单略微偏离屏幕,但当我在 iPhone 上尝试时它根本不可见。

Plugging my phone into my computer, so I can use the console in Safari, I navigated down to where the burger is and I see for .burger :将我的手机插入我的电脑,这样我就可以使用 Safari 中的控制台,我向下导航到汉堡所在的位置,我看到了.burger

padding: 0px 80px 0px 500px;

Commenting that out allows me to see the menu on my phone, suggesting that it is a sizing issue.评论出来让我看到我手机上的菜单,这表明这是一个尺寸问题。

Based on my experience, you are probably better off positioning the burger menu using static or fixed positioning, relative to the top and right (for right hand-side menus) so that it works with any mobile screen width.根据我的经验,您最好使用staticfixed定位来定位汉堡菜单,相对于顶部和右侧(对于右侧菜单),以便它适用于任何移动屏幕宽度。 Note, I am not a CSS expert, but this has worked for me.请注意,我不是 CSS 专家,但这对我有用。

I changed the definition of .burger to be as follows, based on the above comments, which worked for me:根据以上对我有用的评论,我将.burger的定义更改为如下:

.burger {
  display: block;
  position: absolute;
  right: 20px;
}

There is no top position here since the parent is already offset from the top, so while we could set top: 0 it feels a little redundant.这里没有top position 因为父级已经从顶部偏移了,所以虽然我们可以设置top: 0感觉有点多余。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM