我无法弄清楚我设计用来滚动y的菜单(如果它不在屏幕上)。
我尝试通过将overflow-y
设置为auto
来尝试,但是没有用。并设置高度会将导航移到顶部。
有关完整的示例代码,请使用code project url
任何解决该问题的帮助将不胜感激。
body{
background: #CCC;
}
.knl-primary-nav {
display: flex;
justify-content: space-between;
align-items: center;
position: fixed;
top: 0;
left: 5%;
right: 5%;
height: 5em;
line-height: 5em;
width: inherit;
max-width: inherit;
margin: 0 auto;
z-index: 999;
}
.knl-primary-nav .logo {
background: white;
padding: 0 1.5em;
transform:skewX(20deg);
}
.knl-primary-nav .logo>* {
display: block;
transform: skew(-20deg);
}
.knl-primary-nav .logo h1 {
height: 1em;
width: auto;
display: block;
}
.knl-primary-nav .toggle-icon,
.knl-primary-nav input[type=checkbox] {
display: none;
color: #e71715;
}
.knl-primary-nav ul {
display: flex;
justify-content: flex-end;
padding: 0;
list-style: none;
}
.knl-primary-nav ul>li>a{
background: #FFFFFF;
display: block;
text-align: center;
padding: 0 2em;
color: #000000;
text-decoration: none;
}
.knl-primary-nav>ul>li>a{
transform: skewX(20deg);
}
.knl-primary-nav>ul>li>a>span{
transform: skew(-20deg);
display: block;
}
.knl-primary-nav ul li.current-menu-item a, .knl-primary-nav ul li a:hover{
background: #e71715;
color: #FFFFFF;
}
.knl-primary-nav>ul>li.current-menu-item>a, .knl-primary-nav>ul>li>a:hover{
transform: skewX(20deg) scaleY(1.3);
}
.knl-primary-nav>ul>li.current-menu-item>a>span, .knl-primary-nav>ul>li>a:hover>span{
transform: skewX(-20deg) scaleY(0.76);
}
.knl-primary-nav>ul>li>ul{
position: absolute;
display: none;
flex-direction: column;
}
.knl-primary-nav>ul>li>ul>li{
line-height: 2em;
}
.knl-primary-nav>ul>li.menu-item-has-children:hover>ul{
display: flex;
}
.knl-primary-nav>ul>li>ul a:hover{
background: #e71715;
color: #FFF;
}
@media screen and (max-width:768px){
.knl-primary-nav {
line-height: 1.5;
height: 4em;
/*line-height: 4em;*/
}
.knl-primary-nav .logo img {
height: 4em;
}
.knl-primary-nav ul {
display: none;
}
.knl-primary-nav .toggle-icon {
display: inline-block;
margin-bottom: 0;
}
input[type=checkbox]:checked~ul {
position: absolute;
top: 4.5em;
display: flex;
flex-direction: column;
width: 100%;
margin: 0 auto;
}
.knl-primary-nav>ul>li a,.knl-primary-nav>ul>li a:hover,
.knl-primary-nav>ul>li.current-menu-item a{
transform: skewX(0deg);
line-height: 2em;
text-align: left;
}
.knl-primary-nav>ul>li>ul{
display:flex;
position: relative;
}
.knl-primary-nav>ul>li>ul>li{
list-style:
}
.knl-primary-nav>ul>li>ul a{
padding-left: 50px;
}
}
<link href="https://use.fontawesome.com/releases/v5.6.3/css/all.css" rel="stylesheet"/>
<nav class="knl-primary-nav" style="background: transparent; left: 5%; right: 5%; padding: 0px;">
<div class="logo">
<a href="https://devs.kodenlogix.com/mtmgrp/mtmglobal"><h1>LOGO</h1></a>
</div>
<label for="navmenu" class="toggle-icon"><span><i class="fa fa-bars fa-3x"></i></span></label>
<input type="checkbox" id="navmenu">
<ul id="knl-primary-menu" class="menu"><li id="menu-item-18" class=""><a href="#"><span>Home</span></a></li>
<li class="current-menu-parent current_page_parent current_page_ancestor menu-item-has-children"><a href="#"><span>Link 1</span></a>
<ul class="sub-menu">
<li><a href="#"><span>Sub Link 1</span></a></li>
<li><a href="#"><span>Sub Link 2</span></a></li>
<li><a href="#"><span>Sub Link 3</span></a></li>
</ul>
</li>
</ul> </nav>
答案 0 :(得分:0)
下面是导航栏移动菜单的解决方案。
body{
background: #CCC;
}
.knl-primary-nav {
display: flex;
justify-content: space-between;
align-items: center;
position: fixed;
top: 0;
left: 5%;
right: 5%;
height: 5em;
line-height: 5em;
width: inherit;
max-width: inherit;
margin: 0 auto;
z-index: 999;
}
.knl-primary-nav .logo {
background: white;
padding: 0 1.5em;
transform:skewX(20deg);
}
.knl-primary-nav .logo>* {
display: block;
transform: skew(-20deg);
}
.knl-primary-nav .logo h1 {
height: 1em;
width: auto;
display: block;
}
.knl-primary-nav .toggle-icon,
.knl-primary-nav input[type=checkbox] {
display: none;
color: #e71715;
}
.knl-primary-nav ul {
display: flex;
justify-content: flex-end;
padding: 0;
list-style: none;
}
.knl-primary-nav ul>li>a{
background: #FFFFFF;
display: block;
text-align: center;
padding: 0 2em;
color: #000000;
text-decoration: none;
}
.knl-primary-nav>ul>li>a{
transform: skewX(20deg);
}
.knl-primary-nav>ul>li>a>span{
transform: skew(-20deg);
display: block;
}
.knl-primary-nav ul li.current-menu-item a, .knl-primary-nav ul li a:hover{
background: #e71715;
color: #FFFFFF;
}
.knl-primary-nav>ul>li.current-menu-item>a, .knl-primary-nav>ul>li>a:hover{
transform: skewX(20deg) scaleY(1.3);
}
.knl-primary-nav>ul>li.current-menu-item>a>span, .knl-primary-nav>ul>li>a:hover>span{
transform: skewX(-20deg) scaleY(0.76);
}
.knl-primary-nav>ul>li>ul{
position: absolute;
display: none;
flex-direction: column;
}
.knl-primary-nav>ul>li>ul>li{
line-height: 2em;
}
.knl-primary-nav>ul>li.menu-item-has-children:hover>ul{
display: flex;
}
.knl-primary-nav>ul>li>ul a:hover{
background: #e71715;
color: #FFF;
}
@media screen and (max-width:768px){
.knl-primary-nav {
line-height: 1.5;
height: 4em;
/*line-height: 4em;*/
}
.knl-primary-nav .logo img {
height: 4em;
}
.knl-primary-nav ul {
display: none;
}
.knl-primary-nav .toggle-icon {
display: inline-block;
margin-bottom: 0;
}
input[type=checkbox]:checked~ul {
position: absolute;
top: 4.5em;
display: block;
flex-direction: column;
width: 100%;
height:150px;
margin: 0 auto;
overflow-y:scroll;
}
.knl-primary-nav>ul>li a,.knl-primary-nav>ul>li a:hover,
.knl-primary-nav>ul>li.current-menu-item a{
transform: skewX(0deg);
line-height: 2em;
text-align: left;
}
.knl-primary-nav>ul>li>ul{
display:flex;
position: relative;
}
.knl-primary-nav>ul>li>ul>li{
list-style:
}
.knl-primary-nav>ul>li>ul a{
padding-left: 50px;
}
}
<link href="https://use.fontawesome.com/releases/v5.6.3/css/all.css" rel="stylesheet"/>
<nav class="knl-primary-nav" style="background: transparent; left: 5%; right: 5%; padding: 0px;">
<div class="logo">
<a href="https://devs.kodenlogix.com/mtmgrp/mtmglobal"><h1>LOGO</h1></a>
</div>
<label for="navmenu" class="toggle-icon"><span><i class="fa fa-bars fa-3x"></i></span></label>
<input type="checkbox" id="navmenu">
<ul id="knl-primary-menu" class="menu"><li id="menu-item-18" class=""><a href="#"><span>Home</span></a></li>
<li class="current-menu-parent current_page_parent current_page_ancestor menu-item-has-children"><a href="#"><span>Link 1</span></a>
<ul class="sub-menu">
<li><a href="#"><span>Sub Link 1</span></a></li>
<li><a href="#"><span>Sub Link 2</span></a></li>
<li><a href="#"><span>Sub Link 3</span></a></li>
</ul>
</li>
</ul> </nav>