将汉堡菜单创建为网格布局(无 javascript)

Create an hamburger menu into a grid layout (without javascript)

首先,我是法国人,如果我在解释我的问题时犯了一些错误,我深表歉意,因为我的英语并不完美。我也是一名网页设计师,基本上不是纯粹的开发人员,这就是为什么我在这里寻求帮助(并且因为我没有在网上找到我的问题的完美答案)。

我需要使用网格布局为移动/平板设备创建汉堡菜单。

我希望点击它时的样子 https://i.stack.imgur.com/Xh5sV.png

我希望菜单在单击时看起来像它(基于 320 像素宽度的设备)。未点击时,#menu-ul 会隐藏 (-767px),您可以看到页面内容。

目前我的代码如下所示:

body {
display: grid; 
}

#back-top {
position: fixed;
bottom: 40px;
right: 14px;
z-index: 9995;
width: 35px; 
height: 35px;
text-align: center;
font-size: 45px;
font-family: 'Agency FB', arial;
line-height: 32px;
background: #22cfb5;
color: #fff;
cursor: pointer;
border-radius: 50%;
transform: rotate(-90deg);
-o-transition:background-color .5s;
-ms-transition:background-color .5s;
-moz-transition:background-color .5s;
-webkit-transition:background-color .5s;
 transition:background-color .5s;
text-decoration: none;
}

#back-top:hover {
background: #4c4bbf;
}

header {
position: sticky;
top: 0;
z-index: 9999;
}

#navcontainer {
background-color: #4c4bbf;
}

.menu span {
display: block;
width: 19px;
height: 2px;
margin-bottom: 3px;
position: relative;
background: #ffffff; 
z-index: 1;
transform-origin: 4px 0px;
transition: transform 0.5s 
cubic-bezier(0.77, 0.2, 0.05, 1.0), background 0.5s 
cubic-bezier(0.77, 0.2, 0.05, 1.0), opacity 0.55s ease;
transition-property: transform, background, opacity;
transition-duration: 0.5s, 0.5s, 0.55s;
transition-timing-function:
cubic-bezier(0.77, 0.2, 0.05, 1),
cubic-bezier(0.77, 0.2, 0.05, 1),
ease;
transition-delay: 0s, 0s, 0s;
}

.menu input {
display: block;
width: 19px;
height: 13px; 
position: absolute;
cursor: pointer;
opacity: 0;
z-index: 2;
}

.menu input:checked~span {
opacity: 1;
transform: rotate(-45deg) translate(-2px, -1px);
}

.menu input:checked~span:nth-last-child(3) {
opacity: 0;
transform: rotate(0deg) scale(0.2, 0.2);
}

.menu input:checked~span:nth-last-child(2) {
transform: rotate(45deg) translate(-2px, -1px);
}

@media (max-width: 767px) {
body {
  grid-template-columns: repeat(6, 1fr);
  grid-template-rows: 4.375rem 60.625rem 33.75rem 102.6875rem 103.75rem 
  74.375rem 11.1875rem;
  gap: 0px 20px;
}

header {
  grid-column: 1 / span 6;
  grid-row: 1 / span 1; 
} 

#navcontainer {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  grid-template-rows: 4.375rem;
  column-gap: 10px;
  place-items: center;
}

.logo {
  grid-column: 1 / span 5; 
}

.menu {
  grid-column: 6 / span 1;
}

#menu-ul {
  background: linear-gradient(-30deg,#6633ff,#6666ff);
  z-index: 9998;
  grid-column: 1 / span 6; 
  grid-row: 1 / span 7;
  position: absolute;
  width: 100%;
  left: -767px;
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  grid-template-rows: 4.375rem 60.625rem 33.75rem 102.6875rem 103.75rem 74.375rem 11.1875rem;
  gap: 0px 20px;
  transition: transform .3s ease-in-out;
}

ul {
  grid-column: 2 / span 4;
  grid-row: 1 / span 3;
  list-style-type: none;
  -webkit-font-smoothing: antialiased;
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  grid-template-rows: 4.375rem 4.375rem 4.375rem 4.375rem 4.375rem 4.375rem 
  4.375rem;
  place-items: center;
}

.menu input:checked~#menu-ul {
  transform: translateX(767px);
}

.a-menu1 {
  grid-column: 2 / span 4;
  grid-row: 1 / span 3;
}

.a-menu2 {
  grid-column: 2 / span 4;
  grid-row: 2 / span 3;
}

.a-menu3 {
  grid-column: 2 / span 4;
  grid-row: 3 / span 3;
}

.a-menu4 {
  grid-column: 2 / span 4;
  grid-row: 4 / span 3;
}

#linkedin-menu {
  height: 28px;
  width: 28px;
  grid-column: 1 / span 3;
  grid-row: 6  / span 2;
}

#insta-menu {
  height: 28px;
  width: 28px;
  grid-column: 4 / span 3;
  grid-row: 6  / span 2;
}
}
<body>
<a href="#" id="back-top" title="Back top">></a>
<header>
    <nav role="navigation" id="navcontainer">
        <div class="logo">
            <img src="../logo_249.png">
        </div>
        <div class="menu">
            <input type="checkbox"/>
            <span></span>
            <span></span>
            <span></span>
        </div>
    </nav>
</header>

<div id="menu-ul">
    <ul>
        <a class="a-menu1" href="#bienvenue"><li>À propos</li></a>
        <a class="a-menu2" href="#services"><li>Mes services</li></a>
        <a class="a-menu3" href="#projets"><li>Mes projets</li></a>
        <a class="a-menu4" href="#contact"><li>Contact</li></a>
        <img src="img/linkedin-white.png" id="linkedin-menu">
        <img src="img/insta-white.png" id="insta-menu">
    </ul>
</div> 
<!-- + all the remaining content of the page, hidden by the menu ul list when clicked -->
</body>

有了这段代码,我遇到了很多问题:首先,我基本上无法在单击复选框/汉堡菜单时切换#menu-ul。

第二次,我已经尝试将我的整个#menu-ul 放入 .menu 中,并且从那里切换可以工作,但我得到了一个奇怪的结果(#menu-ul 覆盖了 .menu 的一部分nav / header,变成十字的跨度因此被打破)。

最后,我还想用十字键+点击我的主播菜单(Instagram / LinkedIn 除外 target:_blank)让我的#menu-ul 回到隐藏/关闭状态-画布位置。

有没有人可以帮我解决这个问题,并且解释一下,这样我以后就不会再遇到困难了?谢谢,如果您需要更多信息,我可以给您这个:)

你需要这种输出吗?如果需要,请告诉我 我会妥善管理你的代码。