如何修复移动应用程序中的菜单,以便单击后可以将其打开?

时间:2019-01-13 12:49:28

标签: javascript html css asp.net asp.net-mvc

<script>
function myFunction() {
  var x = document.getElementById("myTopnav");
  if (x.className === "topnav") {
    x.className += " responsive";
  } else {
    x.className = "topnav";
  }
}
</script>
.fa1{display:inline-block;font:normal normal normal 14px/1 FontAwesome;
font-size:inherit;text-rendering:auto;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale}

.fa-caret-down1:before{content:"\f0d7"}

.topnav {
  width:100%;
  position:absolute;
  overflow: hidden;
  background-color: rgba(13, 183, 196, 0.7);
  margin-top:250px;
}

.topnav a {
  float: left;
  display: block;
  color: #f2f2f2;
  text-align: center;
  padding: 14px 16px;
  text-decoration: none;
  font-size: 17px;
}

.topnav .icon {
  display: none;
}

.dropdownList1 {
  float: left;
  overflow: hidden;
}
.dropdownList2 {
  float: left;
  overflow: hidden;
}
.dropdownList3 {
  float: left;
  overflow: hidden;
}

.dropdownList1 .dropbtn1,
.dropdownList2 .dropbtn1,
.dropdownList3 .dropbtn1   {
  font-size: 17px;    
  border: none;
  outline: none;
  color: white;
  padding: 14px 16px;
  background-color: inherit;
  font-family: inherit;
  margin: 0;
}

.dropdown-content {
  display: none;
  position: fixed;
  background-color: rgba(13, 183, 196, 0.7);
  min-width: 160px;
  box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
  z-index: 1;
}

.dropdown-content a {
  float: none;
  color: #fff;
  padding: 12px 16px;
  text-decoration: none;
  display: block;
  text-align: left;
}

.topnav a:hover, .dropbtn1:hover{
  background-color: #CD5C5C;
  color: white;
}

.dropdown-content a:hover {
  background-color: #CD5C5C;
  color: white;
}

.dropdownList1:hover .dropdown-content,
.dropdownList2:hover .dropdown-content,
.dropdownList3:hover .dropdown-content {
  display: block;
}

@media screen and (max-width: 600px) {
  .topnav a:not(:first-child), .dropdownList1 .dropbtn1,.dropdownList2 .dropbtn1,.dropdownList3 .dropbtn1   {
    display: none;
  }
  .topnav a.icon {
    float: right;
    display: block;
  }
}

@media screen and (max-width: 600px) {
  .topnav.responsive {position: relative;}
  .topnav.responsive .icon {
    position: fixed;
    top:360px;
	  right:0px;
  }
  .topnav.responsive a {
    float: none;
    display: block;
    text-align: left;
  }
  .topnav.responsive .dropdownList1,
  .topnav.responsive .dropdownList2,
  .topnav.responsive .dropdownList3  {float: none;}
  .topnav.responsive .dropdown-content {position: relative;}
  .topnav.responsive .dropdownList1 .dropbtn1,
  .topnav.responsive .dropdownList2 .dropbtn1,
  .topnav.responsive .dropdownList3 .dropbtn1  {
    display: block;
    width: 100%;
    text-align: left;
  }
}
<div class="topnav" id="myTopnav">
  <a href="#home" class="active">Home</a>
  <div class="dropdownList1">
    <button class="dropbtn1">About Us 
	<i class="fa1 fa-caret-down1"></i>
    </button>
    <div class="dropdown-content">
      <a href="#">About Us</a>
    </div>
  </div> 
   <div class="dropdownList2">
    <button class="dropbtn1">Hair Transplantation 
	<i class="fa1 fa-caret-down1"></i>
    </button>
    <div class="dropdown-content">
      <a href="#">Hair Transplantation Price</a>
      <a href="#">Hair Transplantation</a>
    </div>
  </div> 
   <div class="dropdownList3">
    <button class="dropbtn1">Online Support 
	<i class="fa1 fa-caret-down1"></i>
    </button>
    <div class="dropdown-content">
      <a href="#">Online Support </a>
    </div>
  </div> 
  <a href="#about">Contact</a>
  <a href="#contact">Blog</a>
  <a href="javascript:void(0);" style="font-size:15px;" class="icon" onclick="myFunction()">&#9776;</a>
</div>

我试图在asp.net mvc中制作“ topnav”菜单。但是当有人单击其中的图标后,它不会在移动屏幕中打开。在单击图标后,菜单内容不会出现在菜单中。该代码以html格式工作,但不适用于cshtml文件。 html,css或javascript代码是否有错误?

0 个答案:

没有答案