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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T23:48:28+00:00 2026-06-08T23:48:28+00:00

I have some Jquery which will calculate the width of the UL to then

  • 0

I have some Jquery which will calculate the width of the UL to then divide it by the number of list items, giving them a value so the menu fits full width.

The problem is i have menu items which dont show fully as the code is calculating the list item rather than the string length in the A.

Cartridges/Cylinders doesnt show correctly and Garden & DIY is wrapped to the next line.

HTML:

<div class="container">
 <div id="new-menu-lower">
  <ul class="menuul">
   <li class="menuli">
       <a href="/test.aspx">Barbecues</a>
   </li>
      <li class="menuli">
       <a href="/test.aspx">Stoves</a>
   </li>
      <li class="menuli">
       <a href="/test.aspx">Lanterns</a>
   </li>
      <li class="menuli">
       <a href="/test.aspx">Cartridges/Cylinders</a>
   </li>
      <li class="menuli">
       <a href="/test.aspx">Coolers</a>
   </li>
      <li class="menuli">
       <a href="/test.aspx">Boats</a>
   </li>
      <li class="menuli">
       <a href="/test.aspx">Airbeds</a>
   </li>
      <li class="menuli">
       <a href="/test.aspx">Garden & DIY</a>
   </li>
      <li class="menuli">
       <a href="/test.aspx">Toilets</a>
   </li>
  </ul>
 </div>
</div>

JQUERY:

//set the menu li sizes once everything has loaded.
$(document).ready(function() {
    $('div#new-menu-lower ul li').css('width', ($('div#new-menu-lower ul').width() / $('div#new-menu-lower ul li').length));
    $(function() {
        var menuWidth = $('div#new-menu-lower ul').width();
        var listItems = $('div#new-menu-lower > ul > li').length;
        alert('The UL is calculated at: ' + menuWidth + 'px');
        var itemWidth = Math.floor(menuWidth * (1 / listItems)) - 20;
        $('div#new-menu-lower ul li').css('width', itemWidth);
    });
});

CSS:

div.container
{
    clear: both;
    margin: 10px auto 0;
    width:960px;
    border:1px solid red;
    height:700px;
}

div#new-menu-lower {
    border-radius: 3px 3px 3px 3px;
    border-top: 0 solid lightgrey;
    margin: 0 8px 10px;
}

#new-menu-lower ul {
    border: 1px solid orange;
    display: block;
    height: 27px;
}

#new-menu-lower ul li:first-child {
    border-left: 0 solid lightgrey !important;
    border-radius: 7px 0 0 7px;
}

#new-menu-lower ul li {
    background-image: url("http://i45.tinypic.com/16if95z.png");
    background-repeat: repeat;
    border-right: 0 solid lightgrey !important;
    float: left;
    height: 27px;
    padding-left: ;
    padding-right:;
    text-align: center;
    width: 168px;
    margin-left:1px;
}

DEMO:
http://jsfiddle.net/rM9MW/45/

  • 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-06-08T23:48:30+00:00Added an answer on June 8, 2026 at 11:48 pm

    I think you can use a simpler solution. Take a look at this jsfiddle which i’ve created for you.

    You don’t need to use jquery, but only css.

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

Sidebar

Related Questions

I have some jquery which will calculate the items in my menu and assign
I have a page which loads and then I do some JQuery upon it.
I have a jquery function loading a php file which will output some data
I have some jQuery which will be put on multiple different HTML pages which
I have some jquery code which I am trying to translate to YUI. I
I have some tabs using jQuery UI which work just fine, but I want
I have some jQuery code, which attempts to show the first 6 divs on
I have some onchange events setup in jQuery which are used to populate a
I have some javascript which I want to convert to jQuery... I thought it
I have a JQuery control which has some private methods. I would like to

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.