简体   繁体   English

纯CSS下拉菜单问题

[英]Pure CSS dropdown menu issue

simply and shortly, trying to learn code above, but got lost. 简单而短暂地,试图学习上面的代码,但是迷路了。 ie listing 4 links (or w/e to call them) to your menu works just fine with responsive drop down, but if I do more, 5-6 etc, they are not appearing in drop down menu, what's wrong? 例如,列出4个链接(或w / e称呼它们)到您的菜单,可以在响应下拉菜单中正常工作,但是如果我做更多(5-6次)等操作,则它们没有出现在下拉菜单中,这怎么了?

 /* header */ .header { background-color: #fff; box-shadow: 1px 1px 4px 0 rgba(0,0,0,.1); position: fixed; width: 100%; z-index: 3; } .header ul { margin: 0; padding: 0; list-style: none; overflow: hidden; background-color: #fff; } .header li a { display: block; padding: 20px 20px; border-right: 1px solid #f4f4f4; text-decoration: none; } .header li a:hover, .header .menu-btn:hover { background-color: #f4f4f4; } .header .logo { display: block; float: left; font-size: 2em; padding: 10px 20px; text-decoration: none; } /* menu */ .header .menu { clear: both; max-height: 0; transition: max-height .2s ease-out; } /* menu icon */ .header .menu-icon { cursor: pointer; display: inline-block; float: right; padding: 28px 20px; position: relative; user-select: none; } .header .menu-icon .navicon { background: #333; display: block; height: 2px; position: relative; transition: background .2s ease-out; width: 18px; } .header .menu-icon .navicon:before, .header .menu-icon .navicon:after { background: #333; content: ''; display: block; height: 100%; position: absolute; transition: all .2s ease-out; width: 100%; } .header .menu-icon .navicon:before { top: 5px; } .header .menu-icon .navicon:after { top: -5px; } /* menu btn */ .header .menu-btn { display: none; } .header .menu-btn:checked ~ .menu { max-height: 240px; } .header .menu-btn:checked ~ .menu-icon .navicon { background: transparent; } .header .menu-btn:checked ~ .menu-icon .navicon:before { transform: rotate(-45deg); } .header .menu-btn:checked ~ .menu-icon .navicon:after { transform: rotate(45deg); } .header .menu-btn:checked ~ .menu-icon:not(.steps) .navicon:before, .header .menu-btn:checked ~ .menu-icon:not(.steps) .navicon:after { top: 0; } /* 48em = 768px */ @media (min-width: 48em) { .header li { float: left; } .header li a { padding: 20px 30px; } .header .menu { clear: none; float: right; max-height: none; } .header .menu-icon { display: none; } } 
 <header class="header"> <a href="/" class="logo">AGT</a> <input class="menu-btn" type="checkbox" id="menu-btn" /> <label class="menu-icon" for="menu-btn"> <span class="navicon"></span> </label> <ul class="menu"> <li><a href="#">One</a></li> <li><a href="#">Two</a></li> <li><a href="#">Three</a></li> <li><a href="#">Four</a></li> <li><a href="#">Fifth</a></li> <li><a href="#">Six</a></li> <li><a href="#">Seven</a></li> </ul> </header> 

There's fiddle to make it easier: https://jsfiddle.net/ug6f918s/1012/ 为了使它变得更容易,摆弄了许多小提琴: https : //jsfiddle.net/ug6f918s/1012/

Change or edit this class: 更改或编辑此类:

.header .menu-btn:checked ~ .menu {
  max-height: 240px;
}

Right now it prevents your dropdown menu of exceeding 240 pixels. 现在,它可以防止您的下拉菜单超过240像素。

delete the max-height:0; 删除max-height:0;

/* menu */

.header .menu {
clear: both;
*max-height: 0;*
transition: max-height .2s ease-out;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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