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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T11:52:05+00:00 2026-06-14T11:52:05+00:00

I have a little problem with one code. The html: <div id="navigation"> <ul> <li><a

  • 0

I have a little problem with one code.

The html:

<div id="navigation">
 <ul>
  <li><a href="#">Link</a></li>
  <li><a href="#">Link</a></li>
  <li><a href="#">Link</a></li>
  <li><a href="#">Link</a></li>
  <li><a href="#">Link</a></li>
  <li><a href="#">Link</a></li>
  <li><a href="#">Link</a></li>
 </ul>          
</div>

Simple CSS, just to show the problem:

* { margin: 0; padding: 0; }
.shell {  width: 960px; margin: 0 auto; }

#navigation { background: red; height: 18px; }
#navigation ul { float: left; display: inline;  }
#navigation ul li { float: left; display: inline;  }
#navigation ul li a { float: left; display: inline;  font-size:  14px; line-height: 18px; color:#000; }
#navigation ul li a:hover { background:blue; }

And the JS(using jQuery)

var padWidthModule = ($('#navigation').width() - $('#navigation ul').width())%$('#navigation ul li').length,
padWidthParse = parseInt(($('#navigation').width() - $('#navigation ul').width())/$('#navigation ul li').length),
padHalfWidthModule = padWidthParse%2,
padHalfWidthParse = parseInt(padWidthParse/2),
module = (padWidthModule + padHalfWidthModule)%2;
moduleParse = parseInt((padWidthModule + padHalfWidthModule)/2);
if (padHalfWidthModule==0) {
    $('#navigation ul li a').css({
        'paddingLeft': padHalfWidthParse,
        'paddingRight': padHalfWidthParse
    })
}else{
    $('#navigation ul li a').css({
        'paddingLeft': padHalfWidthParse,
        'paddingRight': padHalfWidthParse+1
    })
}
if (module == 0) {
    $('#navigation ul li:last a').css({
        'paddingLeft': padHalfWidthParse+moduleParse,
        'paddingRight': padHalfWidthParse+moduleParse
    })
}else {
    $('#navigation ul li:last a').css({
        'paddingLeft': padHalfWidthParse+moduleParse,
        'paddingRight': padHalfWidthParse+moduleParse+1
    })
}
setTimeout(function() {
    var liSum = 0,
        pixelDifference = 0;
    if($('#navigation ul li:first').position().top != $('#navigation ul li:last').position().top){
        $('#navigation ul li').each(function(){
            liSum += $(this).outerWidth(true);
        })
        pixelDifference = $('#navigation').width()-liSum;
        console.log(liSum)
        $('#navigation ul li:last a').css({
            'paddingLeft': padHalfWidthParse+moduleParse-pixelDifference
        });
    }
}, 1);

Pretty much the code should add dynamically padding to the navigation elements in order to fill the navigation width, without no white spaces.

The problem you ask?
The code is tested under IE6,IE7.IE8,IE9,Safari,Opera,Chrome and works fine with no problem…but the problem is coming from FireFox under Windows 7 and MAC (there is no problem under XP).
In firefox the last element falls under the navigation. If you see in the JS I added just for that a setTimeout function, that it’s only purpose is to fix the buggy FireFox.

But there is more, I left a console.log(liSum) that calculate the width of all the "li" elements after the JS put it’s padding to them and it should show you 597px (under FireFox).
So we have 3px difference that is substracted from the last element…
But lets stop here, doesn’t this sound fishy? We have a box with width 960px, and list elements with sum 957px, who seem that can’t fit in the box…? If my math is right 957<960 so they should fit after all…but nope… (you should notice, that if the problem was that the width of the elements are bigger than 960px I would had substracted their width and the width of the navigation, but this isn’t the case)
So after the substract you will see that there is still some space after the last navigation element. (actually I can hard code it and substract 1 from the last item, that look better, but there will be still some space left)

If the setTimeout is removed, the last element will fall, but if we opened FireBug and remove just 1px from the last element, it will snap to the navigation box, but there will be still a little space at the end.

Any ideas if this is fixable? (and where is the problem coming from)

(sorry if my english is bad)

jsFiddle: http://jsfiddle.net/utWda/

Screens:

(bad) FireFox Win7 (with setTime function): http://i.imgbox.com/adoAy24C.jpg

(bad) FireFox Win7 (without setTime): http://i.imgbox.com/ads6Ldvu.jpg

(good) Opera: http://i.imgbox.com/acqkLzGy.jpg

(good) FireFox XP: http://i.imgbox.com/abudcEOp.jpg

  • 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-14T11:52:06+00:00Added an answer on June 14, 2026 at 11:52 am

    Your problem is presumably that jQuery is screwing you over.

    The way it’s doing that is that jQuery’s width() returns widths rounded to the nearest pixel. But actual widths of CSS boxes don’t have to be integer numbers of pixels. In your case, say each link has a width that’s 0.45px greater than an integer. Then if the sum of the widths after you round them to the nearest pixel is 3px less than your total width, the sum of all 7 link widths will actually be 0.15px larger than the total width, and things will break, as you discovered.

    To fix this, you should use getBoundingClientRect() for size calculations. And complain to the jQuery developers to fix jQuery’s width()…

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

Sidebar

Related Questions

I have a little problem. This is my code: stackPanelShapesContainer = new StackPanel(); InitializeStackPanle();
i have a little problem with my java socket code. I'm writing an android
I using dropkick js to style dropdown forms but have one little problem. What
enter code here I am having a little problem with jquery.empty(). I have some
just having a little issue figuring this jquery problem out. I have a table
I have a little script which demonstrates my problem, here is javascript code of
I have little problem with a replacement of a little part in an url.
I have little problem in regular expressin creation. Expected input: blahblahblah, blahblahblah, 'blahblahblah', blahblahblah,
I have little unusual problem to solve. I need some hint or links to
I have a little problem about the sort direction of a specific column in

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.