多级超级菜单全宽下拉问题
Multi-level Mega Menu Full Width Dropdown Issue
您好,我正在尝试创建一个全宽的多级大型菜单,但其中的内容的最大宽度为 1240 像素。我可以让内容达到最大宽度,但很难让它达到全宽。试图复制类似于 https://www.boots.com/
的内容
这是我目前得到的,如有任何帮助,我们将不胜感激
.newNavDesktop {
z-index: 1;
background: linear-gradient(302.5deg,#294a77 13.9%,#000338);
width: 100vw;
}
.newNavDesktopContent {
display: flex;
flex-flow: row wrap;
position: relative;
}
.nav-menu {
width: 100%;
}
.nav-menu,.nav-menu ul,.nav-menu li,.nav-menu a {
margin: 0;
padding: 0;
line-height: normal;
list-style: none;
display: block;
}
.nav-menu ul {
opacity: 0;
position: absolute;
top: 100%;
left: -9999px;
z-index: 999;
-webkit-transition: opacity .3s;
transition: opacity .3s;
background: grey;
}
.nav-menu li:hover > ul, .nav-menu li:hover > .newWrapContainer .newNavWrap {
left: 0;
opacity: 1;
z-index: 1000;
}
.nav-menu ul li:hover > ul {
top: 0;
left: 100%;
}
.nav-menu li {
cursor: default;
float: left;
white-space: nowrap;
width: 12em;
}
.nav-menu ul li {
float: none;
}
.nav-menu a {
padding: 0 10px;
color: #5BC0DE;
font-weight: normal;
font-size: 14px;
line-height: 40px;
text-decoration: none;
}
.nav-menu > li > .nav-active {
}
.nav-menu a:hover,.nav-menu a:focus,.nav-menu li:hover a {
text-decoration: underline;
}
.nav-menu li li a,.nav-menu li:hover li a {
padding: 8px 10px;
color: black;
font-size: 12px;
line-height: normal;
text-decoration: none;
}
.nav-menu li:hover li a:hover,.nav-menu li:hover li a:focus {
text-decoration: underline;
}
.nav-menu li:hover li:hover a:hover {
text-decoration: underline;
}
.newWrapContainer .newNavWrap {
background: grey;
max-width: 1240px;
margin: 0 auto;
}
.newWrapContainer {
width: 100vw;
}
<section class="newNavDesktop"><section class="newNavDesktopContent">
<ul class="nav-menu nav-center">
<li><a href="#" class="nav-active">Shop By</a>
<div class="newWrapContainer">
<ul class="newNavWrap">
<li><a href="#">Nav Cat 1</a>
<ul>
<li><a href="#">Sub Sub Nav Link</a></li>
<li><a href="#">Sub Sub Nav Link</a></li>
<li><a href="#">Sub Sub Nav Link</a></li>
</ul>
</li>
<li><a href="#">Nav Cat 1</a>
<ul>
<li><a href="#">Sub Sub Nav Link</a></li>
<li><a href="#">Sub Sub Nav Link</a></li>
<li><a href="#">Sub Sub Nav Link</a></li>
</ul>
</li>
<li><a href="#">Nav Cat 1</a>
<ul>
<li><a href="#">Sub Sub Nav Link</a></li>
<li><a href="#">Sub Sub Nav Link</a></li>
<li><a href="#">Sub Sub Nav Link</a></li>
</ul>
</li>
<li><a href="#">Nav Cat 1</a>
<ul>
<li><a href="#">Sub Sub Nav Link</a></li>
<li><a href="#">Sub Sub Nav Link</a></li>
<li><a href="#">Sub Sub Nav Link</a></li>
</ul>
</li>
</ul>
</div>
</li>
<li><a href="#" class="nav-active">Shop By Category</a>
<div class="newWrapContainer">
<ul class="newNavWrap">
<li><a href="#">Nav Cat 2</a>
<ul>
<li><a href="#">Sub Sub Nav Link</a></li>
<li><a href="#">Sub Sub Nav Link</a></li>
<li><a href="#">Sub Sub Nav Link</a></li>
</ul>
</li>
<li><a href="#">Nav Cat 2</a>
<ul>
<li><a href="#">Sub Sub Nav Link</a></li>
<li><a href="#">Sub Sub Nav Link</a></li>
<li><a href="#">Sub Sub Nav Link</a></li>
</ul>
</li>
<li><a href="#">Nav Cat 2</a>
<ul>
<li><a href="#">Sub Sub Nav Link</a></li>
<li><a href="#">Sub Sub Nav Link</a></li>
<li><a href="#">Sub Sub Nav Link</a></li>
</ul>
</li>
<li><a href="#">Nav Cat 2</a>
<ul>
<li><a href="#">Sub Sub Nav Link</a></li>
<li><a href="#">Sub Sub Nav Link</a></li>
<li><a href="#">Sub Sub Nav Link</a></li>
</ul>
</li>
<li><a href="#">Nav Cat 2</a>
<ul>
<li><a href="#">Sub Sub Nav Link</a></li>
<li><a href="#">Sub Sub Nav Link</a></li>
<li><a href="#">Sub Sub Nav Link</a></li>
</ul>
</li>
</ul>
</div>
</li>
<li><a href="#" class="nav-active">Shop By Brand</a>
<div class="newWrapContainer">
<ul class="newNavWrap">
<li><a href="#">Sub Nav Link</a>
<ul>
<li><a href="#">Sub Sub Nav Link</a>
<ul>
<li><a href="#">Sub Sub Nav Link</a></li>
<li><a href="#">Sub Sub Nav Link</a></li>
<li><a href="#">Sub Sub Nav Link</a></li>
</ul>
</li>
<li><a href="#">Sub Sub Nav Link</a>
<ul>
<li><a href="#">Sub Sub Nav Link</a></li>
<li><a href="#">Sub Sub Nav Link</a></li>
<li><a href="#">Sub Sub Nav Link</a></li>
</ul>
</li>
<li><a href="#">Sub Sub Nav Link</a></li>
</ul>
</li>
<li><a href="#">Sub Nav Link</a>
<ul>
<li><a href="#">Sub Sub Nav Link</a></li>
<li><a href="#">Sub Sub Nav Link</a></li>
<li><a href="#">Sub Sub Nav Link</a></li>
</ul>
</li>
<li><a href="#">Sub Nav Link</a>
<ul>
<li><a href="#">Sub Sub Nav Link</a></li>
<li><a href="#">Sub Sub Nav Link</a></li>
<li><a href="#">Sub Sub Nav Link</a></li>
</ul>
</li>
<li><a href="#">Sub Nav Link</a>
<ul>
<li><a href="#">Sub Sub Nav Link</a></li>
<li><a href="#">Sub Sub Nav Link</a></li>
<li><a href="#">Sub Sub Nav Link</a></li>
</ul>
</li>
</ul>
</div>
</li>
</ul>
</section></section>
将您的包装器 (.newNavDesktop
) 用于菜单并应用 width: 100vw
和 CSS,这将使其始终覆盖视口的整个宽度。将相同的 width: 100vw
应用于下拉元素。为此,我将在下拉列表周围引入 div。
然后 ul 本身可以有一个 max-width: 1024px
。这样下拉菜单可以有灰色背景并跨越整个屏幕,而列表最多只能跨越 1024px。
我创建了一个 Codepen 来更好地说明我认为是您问题的解决方案:https://codepen.io/Nice2MeatU/pen/ZEpLdbK
您好,我正在尝试创建一个全宽的多级大型菜单,但其中的内容的最大宽度为 1240 像素。我可以让内容达到最大宽度,但很难让它达到全宽。试图复制类似于 https://www.boots.com/
的内容这是我目前得到的,如有任何帮助,我们将不胜感激
.newNavDesktop {
z-index: 1;
background: linear-gradient(302.5deg,#294a77 13.9%,#000338);
width: 100vw;
}
.newNavDesktopContent {
display: flex;
flex-flow: row wrap;
position: relative;
}
.nav-menu {
width: 100%;
}
.nav-menu,.nav-menu ul,.nav-menu li,.nav-menu a {
margin: 0;
padding: 0;
line-height: normal;
list-style: none;
display: block;
}
.nav-menu ul {
opacity: 0;
position: absolute;
top: 100%;
left: -9999px;
z-index: 999;
-webkit-transition: opacity .3s;
transition: opacity .3s;
background: grey;
}
.nav-menu li:hover > ul, .nav-menu li:hover > .newWrapContainer .newNavWrap {
left: 0;
opacity: 1;
z-index: 1000;
}
.nav-menu ul li:hover > ul {
top: 0;
left: 100%;
}
.nav-menu li {
cursor: default;
float: left;
white-space: nowrap;
width: 12em;
}
.nav-menu ul li {
float: none;
}
.nav-menu a {
padding: 0 10px;
color: #5BC0DE;
font-weight: normal;
font-size: 14px;
line-height: 40px;
text-decoration: none;
}
.nav-menu > li > .nav-active {
}
.nav-menu a:hover,.nav-menu a:focus,.nav-menu li:hover a {
text-decoration: underline;
}
.nav-menu li li a,.nav-menu li:hover li a {
padding: 8px 10px;
color: black;
font-size: 12px;
line-height: normal;
text-decoration: none;
}
.nav-menu li:hover li a:hover,.nav-menu li:hover li a:focus {
text-decoration: underline;
}
.nav-menu li:hover li:hover a:hover {
text-decoration: underline;
}
.newWrapContainer .newNavWrap {
background: grey;
max-width: 1240px;
margin: 0 auto;
}
.newWrapContainer {
width: 100vw;
}
<section class="newNavDesktop"><section class="newNavDesktopContent">
<ul class="nav-menu nav-center">
<li><a href="#" class="nav-active">Shop By</a>
<div class="newWrapContainer">
<ul class="newNavWrap">
<li><a href="#">Nav Cat 1</a>
<ul>
<li><a href="#">Sub Sub Nav Link</a></li>
<li><a href="#">Sub Sub Nav Link</a></li>
<li><a href="#">Sub Sub Nav Link</a></li>
</ul>
</li>
<li><a href="#">Nav Cat 1</a>
<ul>
<li><a href="#">Sub Sub Nav Link</a></li>
<li><a href="#">Sub Sub Nav Link</a></li>
<li><a href="#">Sub Sub Nav Link</a></li>
</ul>
</li>
<li><a href="#">Nav Cat 1</a>
<ul>
<li><a href="#">Sub Sub Nav Link</a></li>
<li><a href="#">Sub Sub Nav Link</a></li>
<li><a href="#">Sub Sub Nav Link</a></li>
</ul>
</li>
<li><a href="#">Nav Cat 1</a>
<ul>
<li><a href="#">Sub Sub Nav Link</a></li>
<li><a href="#">Sub Sub Nav Link</a></li>
<li><a href="#">Sub Sub Nav Link</a></li>
</ul>
</li>
</ul>
</div>
</li>
<li><a href="#" class="nav-active">Shop By Category</a>
<div class="newWrapContainer">
<ul class="newNavWrap">
<li><a href="#">Nav Cat 2</a>
<ul>
<li><a href="#">Sub Sub Nav Link</a></li>
<li><a href="#">Sub Sub Nav Link</a></li>
<li><a href="#">Sub Sub Nav Link</a></li>
</ul>
</li>
<li><a href="#">Nav Cat 2</a>
<ul>
<li><a href="#">Sub Sub Nav Link</a></li>
<li><a href="#">Sub Sub Nav Link</a></li>
<li><a href="#">Sub Sub Nav Link</a></li>
</ul>
</li>
<li><a href="#">Nav Cat 2</a>
<ul>
<li><a href="#">Sub Sub Nav Link</a></li>
<li><a href="#">Sub Sub Nav Link</a></li>
<li><a href="#">Sub Sub Nav Link</a></li>
</ul>
</li>
<li><a href="#">Nav Cat 2</a>
<ul>
<li><a href="#">Sub Sub Nav Link</a></li>
<li><a href="#">Sub Sub Nav Link</a></li>
<li><a href="#">Sub Sub Nav Link</a></li>
</ul>
</li>
<li><a href="#">Nav Cat 2</a>
<ul>
<li><a href="#">Sub Sub Nav Link</a></li>
<li><a href="#">Sub Sub Nav Link</a></li>
<li><a href="#">Sub Sub Nav Link</a></li>
</ul>
</li>
</ul>
</div>
</li>
<li><a href="#" class="nav-active">Shop By Brand</a>
<div class="newWrapContainer">
<ul class="newNavWrap">
<li><a href="#">Sub Nav Link</a>
<ul>
<li><a href="#">Sub Sub Nav Link</a>
<ul>
<li><a href="#">Sub Sub Nav Link</a></li>
<li><a href="#">Sub Sub Nav Link</a></li>
<li><a href="#">Sub Sub Nav Link</a></li>
</ul>
</li>
<li><a href="#">Sub Sub Nav Link</a>
<ul>
<li><a href="#">Sub Sub Nav Link</a></li>
<li><a href="#">Sub Sub Nav Link</a></li>
<li><a href="#">Sub Sub Nav Link</a></li>
</ul>
</li>
<li><a href="#">Sub Sub Nav Link</a></li>
</ul>
</li>
<li><a href="#">Sub Nav Link</a>
<ul>
<li><a href="#">Sub Sub Nav Link</a></li>
<li><a href="#">Sub Sub Nav Link</a></li>
<li><a href="#">Sub Sub Nav Link</a></li>
</ul>
</li>
<li><a href="#">Sub Nav Link</a>
<ul>
<li><a href="#">Sub Sub Nav Link</a></li>
<li><a href="#">Sub Sub Nav Link</a></li>
<li><a href="#">Sub Sub Nav Link</a></li>
</ul>
</li>
<li><a href="#">Sub Nav Link</a>
<ul>
<li><a href="#">Sub Sub Nav Link</a></li>
<li><a href="#">Sub Sub Nav Link</a></li>
<li><a href="#">Sub Sub Nav Link</a></li>
</ul>
</li>
</ul>
</div>
</li>
</ul>
</section></section>
将您的包装器 (.newNavDesktop
) 用于菜单并应用 width: 100vw
和 CSS,这将使其始终覆盖视口的整个宽度。将相同的 width: 100vw
应用于下拉元素。为此,我将在下拉列表周围引入 div。
然后 ul 本身可以有一个 max-width: 1024px
。这样下拉菜单可以有灰色背景并跨越整个屏幕,而列表最多只能跨越 1024px。
我创建了一个 Codepen 来更好地说明我认为是您问题的解决方案:https://codepen.io/Nice2MeatU/pen/ZEpLdbK