Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I think that "display:inline" would do the trick - but the animate function is setting the display to "block" instead of "inline".</p> <p>If it is okay to "snap" into place instead of animating, you could do this instead.</p> <pre><code>&lt;html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"&gt; &lt;head&gt; &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8"/&gt; &lt;script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"&gt;&lt;/script&gt; &lt;title&gt;untitled&lt;/title&gt; &lt;style type="text/css"&gt; ul{list-style:none;background-color:yellow;margin:0;padding:0;white-space:nowrap;display:inline;} li ul{display:inline;} ul li{background-color:aqua;display:inline;} ul li ul{background-color: blue;} ul li ul li{background-color: green;} a, a:link, a:hover, a:visited, a:active{color: black;text-decoration: none;} &lt;/style&gt; &lt;script type="text/javascript"&gt; var $current = null; $(document).ready(function() { $("ul li ul").hide(); // hide submenus by default on load $("ul li a").click(function() { var $sub = $(this).next(); if ($sub.css("display") == "none") { if ($current != null) //$current.animate({ width: 'hide' }); // if you want to only show one sub at a time $current.removeAttr("display").attr({ style: "display:none;" }); $sub.removeAttr("style").attr({ display: "inline" }); $current = $sub; } else { $sub.removeAttr("display").attr({ style: "display:none;" }); $current = null; } }); }); &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;ul&gt; &lt;li&gt; &lt;a href="#"&gt;Top-level 1&lt;/a&gt; &lt;/li&gt; &lt;li&gt; &lt;a href="#"&gt;Top-level 2&lt;/a&gt; &lt;ul&gt; &lt;li&gt;&lt;a href="#"&gt;Bottom Level A1&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#"&gt;Bottom Level A2&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#"&gt;Bottom Level A3&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#"&gt;Bottom Level A4&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; &lt;/li&gt; &lt;li&gt; &lt;a href="#"&gt;Top-level 3&lt;/a&gt; &lt;ul&gt; &lt;li&gt;&lt;a href="#"&gt;Bottom Level B1&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#"&gt;Bottom Level B2&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; &lt;/li&gt; &lt;li&gt; &lt;a href="#"&gt;Top-level 4&lt;/a&gt; &lt;/li&gt; &lt;/ul&gt; &lt;/body&gt; &lt;/html&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload