Медиа-ответ не распознается - PullRequest
0 голосов
/ 08 января 2019

Я пытаюсь иметь меню гамбургера на небольших устройствах. На ноутбуках и настольных компьютерах я бы хотел статичное меню слева. На данный момент ни один из моих медиа-запросов не распознается. Когда я на экране меньше 438, ничего не происходит. Я не получаю меню гамбургера для небольших экранов, и моя панель навигации всегда фиксируется влево. Я использую codepen и хром.

HTML:

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<div class="nav">
<nav id="navbar">
   <!-- "Hamburger menu" / "Bar icon" to toggle the navigation links -->
  <div class="header">
    <a href="javascript:void(0);" class="icon" onclick="myFunction()"><i class="fa fa-bars"></i></a>
  <header><h1>JS Data Structures</h1></header>
  </div>
  <div id="nav-links">
    <a class="nav-link" href="#introduction" rel="internal">Introduction</a>
    <a class="nav-link" href="#arrays" rel="internal">Arrays</a>
    <a class="nav-link" href="#array_methods" rel="internal">Array Methods</a>
    <a class="nav-link" href="#.filter()" rel="internal">.filter()</a>
    <a class="nav-link" href="#.reduce()" rel="internal">.reduce()</a>
  </div>
</nav>
</div>
<main id="main-doc"></main>

CSS:

#nav{
position: relative;
  }
.header{
    display:flex;
    align-items: center;
    flex-direction: row;
    height:100%;
    border-bottom:1px solid;
  border-color: rgba(0,22,22,0.4);
  }
  /* Hide the links inside the navigation menu (except for logo/home) */


  .header a {
  background: black;
  width:20%;
    text-align:center;
    position:relative;
    height:100%;
    color:white;
  }
  #nav-links{
    display: none;
  }
  #nav-links a{
    display: none;
  }


#main-doc{
  position: absolute;
    margin-left: 310px;
    padding: 20px;
}
@media only screen and (min-width: 438px){
   #nav-links{
    display: block; 
  }

#nav-links a{
  display:block;
  text-decoration: none;
  border-bottom: 1px solid ;
    padding: 8px;
    padding-left: 45px;
  color: black;
  border-color: rgba(0,22,22,0.4);

  }

.nav{
     position: fixed;
     left:0;
    min-width: 290px;
  border-right: solid;
  border-color: rgba(0,22,22,0.4);
}
.icon{
  display:none;
}
  .header{
    display:block;
    text-align:center;
    height:100%;
    border-bottom:1px solid;
    border-color: rgba(0,22,22,0.4);
  }
}

1 Ответ

0 голосов
/ 08 января 2019

Объявите свой медиа-запрос внизу. и добавьте их в медиа-запрос:

.icon {
    display: block;
}

То есть стили должны выглядеть следующим образом:

#main-doc{
  position: absolute;
  margin-left: 310px;
  padding: 20px;
}
#nav-links{
  display: block; 
}
#nav-links a{
  display:block;
  text-decoration: none;
  border-bottom: 1px solid ;
  padding: 8px;
  padding-left: 45px;
  color: black;
  border-color: rgba(0,22,22,0.4);
}
.nav{
  position: fixed;
  left:0;
  min-width: 290px;
  border-right: solid;
  border-color: rgba(0,22,22,0.4);
}
.icon{
  display:none;
}
.header{
  display:block;
  text-align:center;
  height:100%;
  border-bottom:1px solid;
  border-color: rgba(0,22,22,0.4);
}
@media only screen and (max-width: 815px){
  #nav{
    position: relative;
  }
  .header{
    display:flex;
    align-items: center;
    flex-direction: row;
    height:100%;
    border-bottom:1px solid;
    border-color: rgba(0,22,22,0.4);
  }
  /* Hide the links inside the navigation menu (except for logo/home) */
  .header a {
    background: black;
    width:20%;
    text-align:center;
    position:relative;
    height:100%;
    color:white;
  }
  #nav-links{
    display: none !important;
  }
  #nav-links a{
    display: none !important;
  }
  .icon {
    display: block;
  }
}
...