HTML   发布时间:2022-04-14  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了html – Mob Nav菜单显示和隐藏媒体查询收缩大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
如果您查看代码,当缩小页面时,菜单会快速显示,然后向下滑动.当页面缩小时,我希望它根本不显示.我不明白为什么会这样.

我假设它可能是#nav而不是input [type =“checkbox”]的转换:检查#nav,但我需要在#nav上有动画.我有一个单独的文件,我只用于移动导航,它工作得很好.一旦我开始处理媒体查询,事情便会向南发展.

这里的小提琴:
https://jsfiddle.net/reizer/fwzsxrnt/

* {margin:0;padding:0;border:0;list-style:none;font-size:100%;font:inherit;vertical-align:baseline;}
/*RESET*/
body {font: 1em Arial,Helvetica,sans-serif;}
#wrapper {
	max-width: 960px;
	margin: auto;
}
#nav {
	display: block;
	max-height: 0em;
	overflow: hidden;
	transition: max-height 0.5s ease;
	-webkit-transition: max-height 0.5s ease;
	-moz-transition: max-height 0.5s ease;
	-o-transition: max-height 0.5s ease;
}
input[type="checkbox"] {
	position: absolute;
	margin-top: -100em;
}
input[type="checkbox"]:checked + #nav{
	max-height: 20em;
}
label {
	BACkground: #9c0;
	cursor: pointer;
	display: block;
	overflow: auto;
	padding-left: 1em;
	BACkground-color: #9C0;
	BACkground: -moz-linear-gradient(top,#99cc00 0%,#85b100 100%);
	BACkground: -webkit-gradient(linear,left top,left bottom,color-stop(0%,#99cc00),color-stop(100%,#85b100));
	BACkground: -webkit-linear-gradient(top,#85b100 100%);
	BACkground: -o-linear-gradient(top,#85b100 100%);
	BACkground: -ms-linear-gradient(top,#85b100 100%);
	BACkground: linear-gradient(to bottom,#85b100 100%);
	filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#99cc00',endColorstr='#85b100',GradientType=0 );
	-webkit-touch-callout: none;
	-webkit-user-SELEct: none;
	-khtml-user-SELEct: none;
	-moz-user-SELEct: none;
	-ms-user-SELEct: none;
	user-SELEct: none;
	color: #FFF;
	font-size: 1.6em;
	line-height: 2.6em;
}
label:after   {
	content: "\f039";
	float: right;
	BACkground-color: #669900;
	padding: 0.2em 0.3em 0.1em;
	margin: 0.5em;
	font: 1.2em FontAwesome;
	border-radius: 0.3em;
	-webkit-box-shadow: inset 0em 0.1em 0.2em 0em rgba(0,0.3);
	-moz-box-shadow: inset 0em 0.1em 0.2em 0em rgba(0,0.3);
	box-shadow: inset 0em 0.1em 0.2em 0em rgba(0,0.3);
}

#nav ul li a {
	BACkground: #690;
	border: solid #90c12f;
	border-width: 1px 0 0;
	text-decoration: none;
	padding: 1em;
	display: block;
	color: #FFF;
}
#nav ul li a:hover,#nav ul li a:active {
	BACkground: #abd728;	
}
@media screen and (min-width: 479pX) {
.d----onttouchshituntilthispoin----t {
}
label {
	display:none;
}
#nav {
	display: table;
	width: 100%;
	max-height: 20em;
	overflow: auto;
}
#nav ul {
	display: table-row;
}
#nav ul li {
	display: table-cell;
}
#nav ul li a {
	color: #000;
	position: relative;
	text-align: center;
	text-indent: 20px;
	border: solid #000;
	border-width: 0 1px 0 0;
	line-height: 3.4em;
	padding: 0px 20px 0px 0px;
	transition: all 0.5s ease;
	-webkit-transition: all 0.5s ease;
	-o-transition: all 0.5s ease;
	-moz-transition: all 0.5s ease;
} #nav ul li:last-child a{Border:nonE}
#nav ul li a:hover {
	position: relative;
	text-indent: 0px;
	padding-right: 40px;
}
#nav ul li a:before {
	font-family: FontAwesome;
	content: "\f078";
	position: absolute;
	right: 1em;
	margin-top: -0.85em;
	visibility: hidden;
	opacity: 0;
	-webkit-transition: all 0.5s ease;
	transition: all 0.5s ease;
	-o-transition: all 0.5s ease;
	-moz-transition: all 0.5s ease;
}
#nav ul li a:hover:before {
	margin-top: 0em;
	visibility: visible;
	opacity: 1;
}

#nav ul li a ul li {
	position: absolute;
	BACkground: #FF0;
	display: block;
	width: 100%;
	height: 0em;
	visibility: hidden;
	opacity: 0;
	border-radius: 0px 0px 5px 5px;
	-moz-border-radius: 0px 0px 5px 5px;
	-webkit-border-radius: 0px 0px 5px 5px;
	-webkit-transition: height 0.5s ease,opacity 0.0s ease 0.5s,visibility 0.0s ease 0.5s;
	transition: height 0.5s ease,visibility 0.0s ease 0.5s;
	-o-transition: height 0.5s ease,visibility 0.0s ease 0.5s;
	-moz-transition: height 0.5s ease,visibility 0.0s ease 0.5s;
}
#nav ul li a:hover ul li {
	visibility: visible;
	opacity: 1;
	height: 1em;
	-webkit-transition:height 0.5s ease;
	transition:height 0.5s ease;
	-o-transition:height 0.5s ease;
	-moz-transition:height 0.5s ease;
}
<div id="wrapper"><div id="logo"></div><label for="toggle">menu</label>
<input type="checkbox" id="toggle">
<div id="nav">
   <ul>
      <li><a href="#">Home<ul><li></li></ul></a></li>
      <li><a href="#">About<ul><li></li></ul></a></li>
      <li><a href="#">Products<ul><li></li></ul></a></li>
      <li><a href="#">FAQ<ul><li></li></ul></a></li>
      <li><a href="#">Support<ul><li></li></ul></a></li>
      <li><a href="#">Contact<ul><li></li></ul></a></li>
   </ul>
</div>
test
</div>

解决方法

只需删除max-height:20em;来自媒体查询中的#nav.

JSFiddle Here

* {
  margin: 0;
  padding: 0;
  border: 0;
  list-style: none;
  font-size: 100%;
  font: inherit;
  vertical-align: baseline;
}
/*RESET*/

body {
  font: 1em Arial,sans-serif;
}
#wrapper {
  max-width: 960px;
  margin: auto;
}
#nav {
  display: block;
  max-height: 0em;
  overflow: hidden;
  transition: max-height 0.5s ease;
  -webkit-transition: max-height 0.5s ease;
  -moz-transition: max-height 0.5s ease;
  -o-transition: max-height 0.5s ease;
}
input[type="checkbox"] {
  position: absolute;
  margin-top: -100em;
}
input[type="checkbox"]:checked + #nav {
  max-height: 20em;
}
label {
  BACkground: #9c0;
  cursor: pointer;
  display: block;
  overflow: auto;
  padding-left: 1em;
  BACkground-color: #9C0;
  BACkground: -moz-linear-gradient(top,#85b100 100%);
  BACkground: -webkit-gradient(linear,#85b100));
  BACkground: -webkit-linear-gradient(top,#85b100 100%);
  BACkground: -o-linear-gradient(top,#85b100 100%);
  BACkground: -ms-linear-gradient(top,#85b100 100%);
  BACkground: linear-gradient(to bottom,#85b100 100%);
  filter: progid: DXImageTransform.Microsoft.gradient(startColorstr='#99cc00',GradientType=0);
  -webkit-touch-callout: none;
  -webkit-user-SELEct: none;
  -khtml-user-SELEct: none;
  -moz-user-SELEct: none;
  -ms-user-SELEct: none;
  user-SELEct: none;
  color: #FFF;
  font-size: 1.6em;
  line-height: 2.6em;
}
label:after {
  content: "\f039";
  float: right;
  BACkground-color: #669900;
  padding: 0.2em 0.3em 0.1em;
  margin: 0.5em;
  font: 1.2em FontAwesome;
  border-radius: 0.3em;
  -webkit-box-shadow: inset 0em 0.1em 0.2em 0em rgba(0,0.3);
  -moz-box-shadow: inset 0em 0.1em 0.2em 0em rgba(0,0.3);
  box-shadow: inset 0em 0.1em 0.2em 0em rgba(0,0.3);
}
#nav ul li a {
  BACkground: #690;
  border: solid #90c12f;
  border-width: 1px 0 0;
  text-decoration: none;
  padding: 1em;
  display: block;
  color: #FFF;
}
#nav ul li a:hover,#nav ul li a:active {
  BACkground: #abd728;
}
@media screen and (min-width: 479pX) {
  .d----onttouchshituntilthispoin----t {} label {
    display: none;
  }
  #nav {
    display: table;
    width: 100%;
    overflow: auto;
  }
  #nav ul {
    display: table-row;
  }
  #nav ul li {
    display: table-cell;
  }
  #nav ul li a {
    color: #000;
    position: relative;
    text-align: center;
    text-indent: 20px;
    border: solid #000;
    border-width: 0 1px 0 0;
    line-height: 3.4em;
    padding: 0px 20px 0px 0px;
    transition: all 0.5s ease;
    -webkit-transition: all 0.5s ease;
    -o-transition: all 0.5s ease;
    -moz-transition: all 0.5s ease;
  }
  #nav ul li:last-child a {
    border: none
  }
  #nav ul li a:hover {
    position: relative;
    text-indent: 0px;
    padding-right: 40px;
  }
  #nav ul li a:before {
    font-family: FontAwesome;
    content: "\f078";
    position: absolute;
    right: 1em;
    margin-top: -0.85em;
    visibility: hidden;
    opacity: 0;
    -webkit-transition: all 0.5s ease;
    transition: all 0.5s ease;
    -o-transition: all 0.5s ease;
    -moz-transition: all 0.5s ease;
  }
  #nav ul li a:hover:before {
    margin-top: 0em;
    visibility: visible;
    opacity: 1;
  }
  #nav ul li a ul li {
    position: absolute;
    BACkground: #FF0;
    display: block;
    width: 100%;
    height: 0em;
    visibility: hidden;
    opacity: 0;
    border-radius: 0px 0px 5px 5px;
    -moz-border-radius: 0px 0px 5px 5px;
    -webkit-border-radius: 0px 0px 5px 5px;
    -webkit-transition: height 0.5s ease,visibility 0.0s ease 0.5s;
    transition: height 0.5s ease,visibility 0.0s ease 0.5s;
    -o-transition: height 0.5s ease,visibility 0.0s ease 0.5s;
    -moz-transition: height 0.5s ease,visibility 0.0s ease 0.5s;
  }
  #nav ul li a:hover ul li {
    visibility: visible;
    opacity: 1;
    height: 1em;
    -webkit-transition: height 0.5s ease;
    transition: height 0.5s ease;
    -o-transition: height 0.5s ease;
    -moz-transition: height 0.5s ease;
  }
<div id="wrapper">
  <div id="logo"></div>
  <label for="toggle">menu</label>
  <input type="checkbox" id="toggle">
  <div id="nav">
    <ul>
      <li><a href="#">Home<ul><li></li></ul></a>
      </li>
      <li><a href="#">About<ul><li></li></ul></a>
      </li>
      <li><a href="#">Products<ul><li></li></ul></a>
      </li>
      <li><a href="#">FAQ<ul><li></li></ul></a>
      </li>
      <li><a href="#">Support<ul><li></li></ul></a>
      </li>
      <li><a href="#">Contact<ul><li></li></ul></a>
      </li>
    </ul>
  </div>
  test
</div>

大佬总结

以上是大佬教程为你收集整理的html – Mob Nav菜单显示和隐藏媒体查询收缩全部内容,希望文章能够帮你解决html – Mob Nav菜单显示和隐藏媒体查询收缩所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。