简体   繁体   中英

w3.css topnav on small screen

On small screens the topnav navigation has to be clicked twice to open. I cannot figure out what is the issue. I would like to achieve of course the state when the user clicks on icon the topnav opens and shows the rest of buttons (in one row). I have to have the search input field always in the topnav.

<!--MAIN NAVBAR-->
<ul class="topnav w3-card-4" id="myTopnav">
<div class="w3-content">
<li class="w3-hide-small"><a href="./index-w3.php"><i class="fa fa-home" title="úvodní strana"></i></a>
  <li>
  <div class="w3-container" id="searchbar">
  <div class="w3-row">
  <form class="w3-container" action="search-w3.php?action=find&amp;list_kind=users" method="post" name="form1">
  <div class="w3-col s10 m10 l10"><input type="text" name="search_string" id="search_string" class="w3-input w3-border-right w3-hover-border-red" placeholder="Vyhledej.."> </div>
  <div class="w3-col s2 m2 l2"><button class="w3-btn w3-white" style=" padding: 8px 16px!important;"><i class="fa fa-search w3-text-hvalur-color"></i></button></div>
  </form>
  </div>
  </div>
  </li>
   <li class="small-right"><a href="javascript:void(0)" onclick="w3_open_keyboard()"><i class="fa fa-keyboard-o"></i></a></li>
  <li class="w3-right" style="cursor:pointer;"><a href="javascript:void(0)" onclick="document.getElementById('id01').style.display='block'"><i class="fa fa-sign-in" title="login"></i></a></li>
  <li class="w3-right"><a href="javascript:void(0)" onclick="w3_open_language()"><i class="fa fa-globe" title="jazyk"></i></a></li>
  <li class="w3-right"><a href="javascript:void(0)" onclick="w3_open()">menu <i class="fa fa-caret-down"></i></a></li>
    <li class="icon">
    <a href="javascript:void(0);" style="font-size:15px;" onclick="myFunction()">☰</a>
  </li>
</ul>
</div>

Please see the whole code on the fiddle

The problem is that your topnav list have 2 classes topnav and w3-card-4 but your javascript for the click only checks for topnav.

here is a working fiddle: http://jsfiddle.net/xrakxv5p/

So change your toggle function to this if u want an easy fix based on your fiddle.

function myFunction(e) {
    var x = document.getElementById("myTopnav");

    if (x.className === "topnav w3-card-4") {
        x.className += " responsive";
    } else {
        x.className = "topnav w3-card-4";
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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