Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6891387
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:24:12+00:00 2026-05-27T06:24:12+00:00

Consider an ordinary 2 levels dropdown menu: HTML <ul class=menu> <li><a href=#>Main item 1</a>

  • 0

Consider an ordinary 2 levels dropdown menu:

HTML

<ul class="menu">
  <li><a href="#">Main item 1</a>
    <ul>
      <li><a href="#">Item 1</a></li>
      <li><a href="#">Item 2</a></li>
      <li><a href="#">Item 3</a></li>
    </ul>
  </li>
  ...
</ul>

CSS

.nav li { position: relative; float: left; }
.nav li a { display: block; }
.nav li ul { position: absolute; left: 0; top: 39px; }
.nav li ul li { float: left; }

I’d like the second level items to be displayed horizontally, all in one line. It’s not a problem, when we define the width of ul.menu ul. But if the number of the second level menu items varies, we can’t know the width and so the items are displayed vertically.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T06:24:13+00:00Added an answer on May 27, 2026 at 6:24 am

    As vishal and Scott Simpson said, display: inline-block; is the way to solve the problem. But this method doesn’t work in every browser (at least for now). If a parent has position: relative, it indirectly determines the maximum width of its children.
    So I wrote the following script.

    $.fn.dropdownNav = function () {
    
        var dropItem = $(this);
    
        // your dropdown menu height
        var menuHeight = 38;
    
        // dropdown menu is not displayed by default, we need to show it
        dropItem.children('ul').show();
    
        // increase the dropdown menu width, until all items fit in one row
        while ( dropItem.children('ul').height() > menuHeight ) {
            dropItem.children('ul').css({ width: '+=1' });
        }
    
        // it is done, let's hide the dropdown menu
        dropItem.children('ul').hide();
    
        // and bind hover events
        dropItem.hover (
            function () { $(this).children('ul').show(); },
            function () { $(this).children('ul').hide(); }
        );
    };
    
    // function call
    $('.nav > li').each(function () { $(this).dropdownNav(); });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider this class: public class TestMap extends HashMap<String, Float> { public static void main(String[]
Consider the following HTML : <a id=add herf=#>add</a> <div class=list> <select> <option>1</option> <option>2</option> </select>
Consider this simplified model in Django: class Item(models.Model): title = models.CharField(max_length=200) pub_date = models.DateTimeField()
Consider these classes. class Base { ... }; class Derived : public Base {
Consider the following situation: public class Storage { public T GetSingleByID<T>(long id) where T
Consider the following code: void Increment(int *arr) { arr++; } int main() { int
Consider these two classes: public class A { B b; public A(B b) {
Consider following simple DAO example: public abstract class DAOFactory { public abstract AccountDAO getAccountDAO();
Consider this HTML: <form id=MyForm> <input name=Input1/> </form> In Script# I do this: FormElement
Consider this code: #include <iostream> int main() { int iTemp = 0; iTemp +=

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.