responsive navbar using display:none still shows even it is meant to show when the screen resized using media query

grasig

i'm trying to fix my responsive navigation bar. supposed to be, when the screen is resized smaller, the navigation will change to a single button which is "menu" and when clicked, it will toggle the navigation vertically. the problem is, even at full screen size, the menu still shows up. this should only appear when screen was changed. thank you

    HTML:
   <div class="nav">
     <ul>
    <li ><a class="active" href="index.php"><a href="#">Home</a></li>
    <li ><a href="">About us</a>
      <ul>
        <li><a href="site_profile.php">Company Profile</a></li>
        <li><a href="#">Management</a></li>
        <li><a href="#">Testimonials</a></li>
        <li><a href="#">Services</a></li>
      </ul>
    </li>
    <li ><a href="#">Contacts</a></li>
    <li ><a href="">Careers</a></li>
    <li ><a href="#">Blog</a>
      <ul>
        <li><a href="#">Tips</a></li>
        <li><a href="#">Success Story</a></li>

      </ul>
    </li>
      <li class="contact"><a href="#">Login</a></li>
  </ul>
  <div class="handle"> Menu </div>
</div>

  CSS:

.nav ul {
  list-style: none;
  background-color: #444;
  text-align: center;
  padding: 0;
  margin: 0; 
}

.nav li {
  font-family: 'Oswald', sans-serif;
  font-size: 1.2em;
  line-height: 40px;
  text-align: left;
}

.nav a {
 text-decoration: none;
 color: #fff;
 display: block;
 padding-left: 15px;
 border-bottom: 1px solid #888;
 transition: .3s background-color;
}

.nav a:hover {
  background-color: #005f5f;
}

.nav a.active {
 background-color: #aaa;
 color: #444;
 cursor: default;
}

/* Sub Menus */
.nav li li {
font-size: .8em;
 }

/*******************************************
 MEDIA
********************************************/
.handle.hidden {
 width: 100%;
 background: white;
 text-align: left;
 box-sizing: border-box;
 padding: 15px 10px;
 cursor: pointer;
 color: white;
 display: none;
 }  

 @media screen and (min-width: 650px) {

.nav li {
 width: 130px;
 border-bottom: none;
 height: 50px;
 line-height: 50px;
 font-size: 1.4em;
 display: inline-block;
 margin-right: -4px;
   }

.showing { max-height: 20em; }

 .nav a {
  border-bottom: none;
  }

 .nav > ul > li {
  text-align: center;
  }

  .nav > ul > li > a {
  padding-left: 0;
  }

  /* Sub Menus */
  .nav li ul {
  position: absolute;
  display: none;
  width: inherit;
  }

 .nav li:hover ul {
 display: block;
  }

 .nav li ul li {
 display: block;
 }
.handle{
    display: block;
    background-color: rgba(0,0,0,0.8);
 }
 }

 SCRIPT:
  <script type="text/javascript">
    $('.handle').on('click', function(){
        $('nav ul').toggleClass('showing');
    });
   </script>
Wazaraki

With your current code you would need to add the class .hidden dinamically to the .menu html element which is not very convenient but there is a simpler way to make the menu disappear. Just try:

.handle { /* now we don't use the .hidden class */
      width: 100%;
      background: white;
      text-align: left;
      box-sizing: border-box;
      padding: 15px 10px;
      cursor: pointer;
      color: white;
      display: block;
 }  

...

/* inside media query */
 @media screen and (min-width: 650px) {
   .handle {
       display: none; /* this hides the menu on bigger screens */
       background-color: rgba(0,0,0,0.8);
    }
 }

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Menu Still Show When Change @media query

From Dev

bootstrap navbar is breaking when screen is resized

From Dev

Media Query - display:none not working

From Dev

How to display: none between parent and sibling tags when using show more show less Jquery

From Dev

How to display multiple columns (2) as one using Bootstrap when shrinking screen (responsive)?

From Dev

Responsive design with media query : screen size?

From Dev

navbar{display: none} class not applied using bootstrap CSS

From Dev

Media Query Not Working display:none to display:inline

From Dev

how to only load one IFRAME using @media and display:none; CSS

From Dev

Using position: 'Absolute' and display: 'None' in React Native still renders the component

From Dev

Icon aligns to center when using display: table and margin: auto, but when I change to display:none it does not align to center after .show()

From Dev

Responsive webpage using media queries

From Dev

Display none not working inside of media query

From Dev

Using the IE8 @media \0screen query in LESS

From Dev

Media Query using Javascript/JQuery - Changing image depending on screen size

From Dev

show hidden div using jQuery after first checking if it is display none

From Dev

How to show resized sidebar using SWRevealViewController?

From Dev

Media query using jquery

From Dev

Responsiveness using Media Query

From Dev

Display a method when div is displaying using show()

From Dev

Show logo in navbar when div scrolled out of view using AngularJS

From Dev

Responsive NavBar Only using CSS and html

From Dev

Responsive website design, navbar won't centre correctly when resized to phone dimensions

From Dev

Show image when iframe viewport is small, using media queries

From Dev

How to make a responsive footer using media queries

From Dev

How to make a responsive footer using media queries

From Dev

When resized, responsive navigation disappears?

From Dev

Display on screen using QAbstractVideoSurface

From Dev

Display on screen using QAbstractVideoSurface

Related Related

  1. 1

    Menu Still Show When Change @media query

  2. 2

    bootstrap navbar is breaking when screen is resized

  3. 3

    Media Query - display:none not working

  4. 4

    How to display: none between parent and sibling tags when using show more show less Jquery

  5. 5

    How to display multiple columns (2) as one using Bootstrap when shrinking screen (responsive)?

  6. 6

    Responsive design with media query : screen size?

  7. 7

    navbar{display: none} class not applied using bootstrap CSS

  8. 8

    Media Query Not Working display:none to display:inline

  9. 9

    how to only load one IFRAME using @media and display:none; CSS

  10. 10

    Using position: 'Absolute' and display: 'None' in React Native still renders the component

  11. 11

    Icon aligns to center when using display: table and margin: auto, but when I change to display:none it does not align to center after .show()

  12. 12

    Responsive webpage using media queries

  13. 13

    Display none not working inside of media query

  14. 14

    Using the IE8 @media \0screen query in LESS

  15. 15

    Media Query using Javascript/JQuery - Changing image depending on screen size

  16. 16

    show hidden div using jQuery after first checking if it is display none

  17. 17

    How to show resized sidebar using SWRevealViewController?

  18. 18

    Media query using jquery

  19. 19

    Responsiveness using Media Query

  20. 20

    Display a method when div is displaying using show()

  21. 21

    Show logo in navbar when div scrolled out of view using AngularJS

  22. 22

    Responsive NavBar Only using CSS and html

  23. 23

    Responsive website design, navbar won't centre correctly when resized to phone dimensions

  24. 24

    Show image when iframe viewport is small, using media queries

  25. 25

    How to make a responsive footer using media queries

  26. 26

    How to make a responsive footer using media queries

  27. 27

    When resized, responsive navigation disappears?

  28. 28

    Display on screen using QAbstractVideoSurface

  29. 29

    Display on screen using QAbstractVideoSurface

HotTag

Archive