简体   繁体   English

如何创建图标菜单?

[英]How create an icon menu?

I have this problem: 我有这个问题:

The standard command that I use to put an icon is: 我用来放置图标的标准命令是:

<a href="" class="icon fa-file-code-o"></a>

But this code just have space for 1 link (I did not found other examples), but I need to redirect for multiple chooses. 但是这段代码只为1个链接留出空间(我没有找到其他示例),但是我需要重定向进行多项选择。 Ie What I want to know is if it is possible to create a ``menu" from an icon, something like that: When I click on the icon they show all the options for the person, like an standard menu 即我想知道的是是否有可能通过图标创建``菜单'',如下所示:当我单击图标时,它们会显示该人的所有选项,例如标准菜单

像这样

If is relevant, the icons are on one table. 如果相关,则图标在一张桌子上。

In general, one does not "create a menu from an icon", you normally create a menu and an icon to it. 通常,不会“从图标创建菜单”,而是通常会创建一个菜单和一个图标。 Your "standard command" is an ordinary HTML-Link with some custom attributes that are then processed by some package running in your environment to create a menu. 您的“标准命令”是具有一些自定义属性的普通HTML链接,然后由您的环境中运行的某些程序包对其进行处理以创建菜单。 But without more info about your environment, it is impossible to give an accurate and satisfying answer. 但是,如果没有有关您的环境的更多信息,就不可能给出准确而令人满意的答案。

Yes, it involves more HTML for the menu, CSS to show 2 states: hidden and showing, and JavaScript for the click event handling. 是的,菜单包含更多HTML,CSS显示2种状态:隐藏和显示,以及Click事件处理的JavaScript。

"(I did not found other examples)" “(我没有找到其他例子)”

I'm going to assume that is true considering your grasp of English. 考虑到您对英语的掌握,我认为这是真的。 Before you say it "doesn't work" , you must post the code that you are working with: HTML, CSS, and JavaScript/jQuery. 在说“不起作用”之前 ,必须发布正在使用的代码:HTML,CSS和JavaScript / jQuery。 Please keep it to a minimum and we'll request more or less as your question progresses. 请保持在最低限度,随着您的问题的进行,我们会或多或少地要求您。

Demo 演示版

 document.querySelector('.fa').onclick = openClose; function openClose(e) { if (e.target.tagName === "A") { e.target.classList.toggle('on'); } else { return false; } } 
 .menu { margin: 0; padding:0; list-style: none; max-height: 0; position: relative; overflow: hidden; transition: .5s ease; background: rgba(0,0,0,0.7); width: fit-content; } .on + .menu { max-height: 500px; position: absolute; transition: .5s ease; } .menu a { color:#FC3; text-decoration:none } .menu li { padding: 5px; } 
 <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" /> <a href="#/" class="fa fa-file-code-o fa-3x"></a> <ul class='menu'> <li><a href='https://stackoverflow.com/questions/tagged/html'>HTML</a></li> <li><a href='https://stackoverflow.com/questions/tagged/css'>CSS</a></li> <li><a href='https://stackoverflow.com/questions/tagged/javascript'>JavaScript</a></li> </ul> 

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

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