在CSS问题中导航栏的汉堡包

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了在CSS问题中导航栏的汉堡包相关的知识,希望对你有一定的参考价值。

我正在自己的网站上工作,目前在切换按钮方面存在问题。当我点击汉堡包菜单时,导航栏不会显示。但是切换栏正在工作。我只是做同样的事情,但我只是结合了两个来源,因为概念是相同的。

源代码:

https://www.youtube.com/watch?v=xMTs8tAapnQ

https://www.youtube.com/watch?v=H1eXpp4DAWQ&list=LLU3FO2sJDhxbIBRVc0fA34A&index=2&t=0s

* 
  margin: 0;
  padding: 0;


#toggle 
  display: none;


.hambuger 
  z-index: 1;
  /*keeps displaying the icon when it clicks*/
  position: fixed;
  width: 25px;
  /*The parents (hamburger) of siblings (span)*/
  top: 20px;
  left: 28px;
  cursor: pointer;
  /*to able to click it*/


.line 
  display: block;
  /*to show the three lines*/
  width: 100%;
  /*Maximize the width of the parents (hamburger: 25px width)*/
  height: 3px;
  margin-bottom: 3px;
  /*to separate and see the icons*/
  background-color: black;
  /*color of the icons*/


.menu 
  display: none;
  width: 70px;
  line-height: 1.7em;
  margin: 40px;


.menu a 
  display: block;
  text-decoration: none;
  color: black;
  border: 1px grey solid;


#toggle:checked~.menu 
  display: block;
  /*The toggle became the parents while menu is the sibling here*/
<header class="content">
  <label for="toggle" class="hambuger">
    <input type="checkbox" id="toggle">
    <span class="line"></span>
    <span class="line"></span>
    <span class="line"></span>
  </label>

  <nav class="menu">
    <a href="#" class="active">Home</a>
    <a href="#" class="active">About us</a>
    <a href="#" class="active">History</a>
    <a href="#" class="active">Contacts</a>
  </nav>
</header>
答案

为了使用通用兄弟选择器〜从输入中选择你的.menu项目,我在同一个父元素(标题元素)中移动输入以使它们成为兄弟姐妹。

* 
  margin: 0;
  padding: 0;


#toggle 
  display: none;


.hambuger 
  z-index: 1;
  /*keeps displaying the icon when it clicks*/
  position: fixed;
  width: 25px;
  /*The parents (hamburger) of siblings (span)*/
  top: 20px;
  left: 28px;
  cursor: pointer;
  /*to able to click it*/


.line 
  display: block;
  /*to show the three lines*/
  width: 100%;
  /*Maximize the width of the parents (hamburger: 25px width)*/
  height: 3px;
  margin-bottom: 3px;
  /*to separate and see the icons*/
  background-color: black;
  /*color of the icons*/


.menu 
  display: none;
  width: 70px;
  line-height: 1.7em;
  margin: 40px;


.menu a 
  display: block;
  text-decoration: none;
  color: black;
  border: 1px grey solid;


#toggle:checked~.menu 
  display: block;
  /*The toggle became the parents while menu is the sibling here*/
<header class="content">
  <input type="checkbox" id="toggle">
  <label for="toggle" class="hambuger">
    <span class="line"></span>
    <span class="line"></span>
    <span class="line"></span>
  </label>
  <nav class="menu">
    <a href="#" class="active">Home</a>
    <a href="#" class="active">About us</a>
    <a href="#" class="active">History</a>
    <a href="#" class="active">Contacts</a>
  </nav>

</header>

以上是关于在CSS问题中导航栏的汉堡包的主要内容,如果未能解决你的问题,请参考以下文章

在移动设备中查看时带有侧边栏的 Bootstrap 导航栏

css CSS折叠导航栏到汉堡图标

请教大家一个关于css水平导航栏的问题?

如何完全覆盖导航栏的后退按钮操作?

如何在 Android 中更改汉堡图标(导航抽屉)

使用奇怪的导航栏的 CSS 悬停问题