How to create a menu tree using HTML

匿名 (未验证) 提交于 2019-12-03 02:24:01

问题:

I need to create a menu tree using HTML. I had a search on Google, but they are providing some software to download in order to create this. But I need some script and HTML tags to do this. Can anyone help me solve this problem. Thanks in advance.

回答1:

Here is something very simple to start with.

http://www.dynamicdrive.com/dynamicindex1/navigate1.htm

EDIT

Implementing what I learned from @sushil bharwani. Here is how I found the above URL i.e. at the courtesy of @sushil bharwani http://www.google.co.in/search?q=Menu+Tree+using+UL+L&qscrl=1



回答2:

You don't need to use JavaScript (unless you want compatibility with outdated browsers), you can achieve it with HTML+CSS alone. And in a much more semantically-correct way. :)

You can make vertical dropdown menus or (prettier example) horizontal menus using the techniques explained in the Sons of Suckerfish article at HTMLDog.
Simple and meaningful.


Sample

Here is a simple example. In it you can see the hover functionality working perfectly.

The CSS is not good, because it's only a sample.
To work on the style, disable the display: none; line: that will stop the submenus from hiding when not hovered, and you can work on styling everything.
When you are done, simply re-enable the display: none; line to get the submenus to hide and only show on hover.

HTML

<nav> <p>Collapsing:</p> <ul class="collapsable">     <li>a<ul>         <li>a1         <li>a2         </ul>     <li>b<ul>         <li>b1         </ul> </ul> <p>Not collapsing:</p> <ul>     <li>a<ul>         <li>a1         <li>a2         </ul>     <li>b<ul>         <li>b1         </ul> </ul> </nav> 

CSS

nav li:hover {     background: #EEEEEE; } nav li>ul {     display: inline-block;     margin: 0;     padding: 0; } nav .collapsable li>ul {     display: none; } nav li>ul::before {     content: ": { "; } nav li>ul::after {     content: " } "; } nav li:hover>ul {     display: inline-block; } nav li>ul>li {     display: inline-block; } nav li>ul>li+li::before {     content: ", "; } 

Here is a jsfiddle: http://jsfiddle.net/x8dxv/



回答3:

With a bit of javascript and a knowledge around CSS you can convert a simple UL LI list to a menu tree. its right that you can use jQuery if you understand it.

You can narrow your google search by Menu Tree using UL Li. or CSS to convert UL LI to tree.



回答4:

Navigation menus are mostly created using a combination of UL and LI.

<UL id="Menu">     <LI>Home</LI>     <LI>Links</LI> </UL> 

And you can insert UL inside LI element and thus get a tree structure for navigation.



回答5:

Here is a simply way to do it if you don't want to write one yourself..

http://www.mycssmenu.com/#css-menu-demo



回答6:

You might want to look into some of the online tools that builds the menu for you. E.g. CSS Menu Generator



回答7:

You could use JavaScript to generate the menu - for example, have a look at the plugin jQuery - Menu tree.



回答8:

I am not sure if you will find your answer, but here is a list with several different types of vertical menus http://css.maxdesign.com.au/listamatic2/index.htm no javascript is involved in those examples



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!