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

  • Home
  • SEARCH
  • 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 9258511
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T12:25:26+00:00 2026-06-18T12:25:26+00:00

I hope someone can help with this. I have written a function which adds

  • 0

I hope someone can help with this.

I have written a function which adds width to a final li item in a nav ul based on the number of existing list items and the remaining width in the parent container.

This works fine on document load and if the document is resized and an href is clicked, but during the actual resize the element’s size is not recalculated.

I’ve made a fiddle to help illustrate this.

Does anyone know how to dynamically make the calculation whilst the window is being resized?

This is the js

 $(document).ready(calcWidth);
$(document).resize(calcWidth);

function calcWidth(){
    // get array of all the list items in the nav
    var $listWidth = $('ul#main-nav li').map(function(){
        return $(this).width();
    }).get();
    var $itemCount = $('#main-nav li').length; //this works as margin-right is set to 1px
    var $contWidth = $('#main-nav').width(); // get the full container width
    var $sum = 0;
    $.each($listWidth,function(){$sum+=parseFloat(this) || 0;});
    $('ul#main-nav li.final a').css({
        width:  $contWidth - $sum - $itemCount, //set the width of the final li to be the total container minus the sum of the existing li elements
        height: '12px'
    });
}

If you need more code posted here, let me know, but it’s all in the fiddle.

Thanks
Luke

  • 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-18T12:25:27+00:00Added an answer on June 18, 2026 at 12:25 pm

    You don’t need to do this with javascript.

    Move the clearfix class on the UL (because the list items are floated), add the purple background on the UL, and a 1px white right border to the list items. And you can remove the last LI.

    See it here

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

Sidebar

Related Questions

Hope someone can help me with this.. I have a magento store up&running, via
I really hope someone can help on this because I'm learning cocoa and have
I hope someone can help with this. I have created a map app that
I hope someone can help me with the following... I have this code below
Hope someone can help with this. I have multiple tables with millions items and
I hope someone can help with this issue. I have a popup iframe using
I really hope someone can help with this problem. I have an ajax pagination
I couldn't find a solution for this yet...hope someone can help me. I have
I hope someone can help me with this Javascript. I have an Object called
I hope someone can help with this. I have a UITableViewController and want 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.