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 981503
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T04:33:08+00:00 2026-05-16T04:33:08+00:00

This is an expansion of a question I posted a while ago: Fitting a

  • 0

This is an expansion of a question I posted a while ago: Fitting a <ul>'s width to accommodate the menu items

Is there a snippet of jQuery code that can adjust the width of every <ul> inside a certain <ul> to make sure the <li> items don’t overflow? The menu looks something like this:

<ul id="menu">
  <li>
    <a href="javascript:;">Menu 1</a>
    <ul>
      <li><a href="javascript:;">Item 1<a></li>
      <li>
        <a href="javascript:;">Subitem 1</a>
        <ul>
          <li><a href="javascript:;">Subsubitem 1</a></li>
        </ul>
      </li>
    </ul>
  </li>
</ul>

If I don’t adjust the <ul> correctly, the layout looks messed up as shown here:

Site menu

You can take a look at the site I’m developing here if you need more information about the CSS or the general structure of the web page.

  • 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-16T04:33:08+00:00Added an answer on May 16, 2026 at 4:33 am

    The width problem actually stems from the width set at the top level here:

    ul#menu > li {
      display: block;
      float: left;
      background: url(img/menuitem.png) top left;
      width: 104px;                                 /* here's the issue */
      height: 36px;
      margin-right: 1px;
      text-align: center;
      position: relative;                           /* add this */
    }
    

    Since it has a width specified, and its child is in the normal flow, its child is obeying its width, rather than scaling by itself. What you can do is take the child out of the flow, by adding position: realtive; like I have in the above style, then give the child <ul> a position: absolute, like this:

    ul#menu > li ul {
      position: absolute;
      top: 36px;              /* top <li> is 36px, go down that much */
    }
    

    Then finally, so the anchor text gets a full background, give it a white-space rule like this:

    ul#menu > li > a, ul#menu > li > ul a {
      display: block;
      text-decoration: none;
      white-space: nowrap;
    }
    

    Here’s what the result looks like:
    alt text

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is an extension to a question which I asked some time ago. I
This is an extension for this question asked an hour ago. We cannot modify
Take the following demo code (from the GIO answer to this question), which uses
This is a expansion on to a previous question that got answered yesterday, which
This question is related to the question posted here: Why isn't my custom WCF
This is an extension of a previously posted question. I'm trying to recursively build
I think this question is a matter of writing nice ruby code, let me
I posted a question a few months ago about sharing resource dictionaries across assemblies
I've seen this question posted here previously but I'm not satisfied that I understand
note: This is an expansion (and clarification) of a question I asked yesterday. I

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.