如何使用多个相邻列表创建下拉列表'
我正在尝试为购物式式订单编写代码,当一个人徘徊在导航栏上的目标元素上时,它的功能与此网站。
我已经花了两天时间来查看许多页面,包括以前的Stackoverflow上的帖子,并尝试了似乎无限数量的方法,但是我根本无法破解这一点。
我应该强调的是,我已经可以为下拉列表编写代码,该下拉列表会在目标元素上徘徊时生成单个链接列表的列(这很容易);我真的在说对齐相邻的多列。
几年前,这里发布了此类问题的解决方案,但该人建议使用浮动方法。我确实尝试了这个,但是结果对我的项目(非常)不满意。
如果您可以帮助我解决这个问题,请(立即)查看我的代码渲染和绘制时的样子,我在 codepen ,但代码也在下面发布:
html:html:
.nav-list {
list-style: none;
border: 1px solid blue;
display: flex;
flex-flow: row wrap;
align-items: left;
justify-content: space-around;
color: white;
background-color: #429CD9;
}
#hire-dropdown {
position: absolute;
cursor: pointer;
background-color: #429CD9;
}
.the-drop {
display: none;
}
#hire-dropdown:hover>.the-drop {
display: grid;
grid-template-areas: "drop-1-list drop-2-list";
grid-template-columns: 1fr 1fr;
}
.drop-1-list,
.drop-2-list {
display: none;
}
.drop-1-list {
grid-area: "drop-1-list";
}
.drop-2-list {
grid-area: "drop-2-list";
}
.the-drop:hover>.drop-1-list,
.the-drop:hover>.drop-2-list {
background-color: white;
border: 1px solid black;
list-style: none;
}
<nav>
<ul class="nav-list">
<li>Nothing</li>
<li class="to-hire">
<div id="hire-dropdown">To Hire
<div class=".the-drop">
<ul class="drop-1-list">
<li><a href="#">Access</a></li>
<li><a href="#">Breaking</a></li>
<li><a href="#">Compaction</a></li>
<li><a href="#">Cooling</a></li>
<li><a href="#">Drilling</a></li>
<li><a href="#">Lifting</a></li>
<li><a href="#">Sanding</a></li>
<li><a href="#">Sawing</a></li>
</ul>
<ul class="drop-2-list">
<li><a href="#">Product 1</a></li>
<li><a href="#">Product 2</a></li>
<li><a href="#">Product 3</a></li>
<li><a href="#">Product 4</a></li>
<li><a href="#">Product 5</a></li>
</ul>
</div>
</div>
</li>
</ul>
</nav>
如果您还想查看我之前提到的float方法解决方案,则可以看到它在这里(但我不认为这是我项目的正确解决方案)。
您的(建设性)帮助将不胜感激。
I'm trying to write code for a shopping-website style dropdown that when one hovers over a target element on the navigation bar, it functions like the one depicted at this site.
I've spent two days on this, looking at so many pages, including previous postings on Stackoverflow, and tried what seems like an endless number of approaches, but I've simply not been able to crack this.
I should stress that I can already write the code for a dropdown that generates a single column of list of links when one hovers over the target element (that's easy); I'm really talking about aligned adjacent multiple columns.
A solution for a problem like this was posted here on Stackoverflow several years ago, but the person suggested the float method. I did actually try this, but the results were (very) unsatisfactory for my project.
If you can help me with this, to (instantly) see what my code looks like when rendered and painted, I've posted the necessary bits of code on Codepen, but the code is also posted below:
HTML:
.nav-list {
list-style: none;
border: 1px solid blue;
display: flex;
flex-flow: row wrap;
align-items: left;
justify-content: space-around;
color: white;
background-color: #429CD9;
}
#hire-dropdown {
position: absolute;
cursor: pointer;
background-color: #429CD9;
}
.the-drop {
display: none;
}
#hire-dropdown:hover>.the-drop {
display: grid;
grid-template-areas: "drop-1-list drop-2-list";
grid-template-columns: 1fr 1fr;
}
.drop-1-list,
.drop-2-list {
display: none;
}
.drop-1-list {
grid-area: "drop-1-list";
}
.drop-2-list {
grid-area: "drop-2-list";
}
.the-drop:hover>.drop-1-list,
.the-drop:hover>.drop-2-list {
background-color: white;
border: 1px solid black;
list-style: none;
}
<nav>
<ul class="nav-list">
<li>Nothing</li>
<li class="to-hire">
<div id="hire-dropdown">To Hire
<div class=".the-drop">
<ul class="drop-1-list">
<li><a href="#">Access</a></li>
<li><a href="#">Breaking</a></li>
<li><a href="#">Compaction</a></li>
<li><a href="#">Cooling</a></li>
<li><a href="#">Drilling</a></li>
<li><a href="#">Lifting</a></li>
<li><a href="#">Sanding</a></li>
<li><a href="#">Sawing</a></li>
</ul>
<ul class="drop-2-list">
<li><a href="#">Product 1</a></li>
<li><a href="#">Product 2</a></li>
<li><a href="#">Product 3</a></li>
<li><a href="#">Product 4</a></li>
<li><a href="#">Product 5</a></li>
</ul>
</div>
</div>
</li>
</ul>
</nav>
If you also want to see the float method solution I referred to earlier, you can see it here (but I do not believe this is the right solution for my project).
Your (constructive) help would be most appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不是100%确定您要如何处理所有狭窄的显示等。但是
&lt; div class =“。the -drop”&gt;
删除标记中类上的绝对
。Not 100% sure how you want to handle all the narrow displays etc. but
<div class=".the-drop">
remove the period on the class in the markupabsolute
I think.jQuery要处理事件,
您的类名称中有一个
。
此处&lt; div class =“。the-drop”&gt;
,将其删除。从CSS中删除这些代码行
现在
Jquery to handle the events
You have a
.
in the class name here<div class=".the-drop">
, remove it.Remove these lines of code from your CSS
Now what should happen is, when your mouse goes onto the dropdown menu link, your dropdown should show, when it leaves it will hide