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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T23:46:50+00:00 2026-05-15T23:46:50+00:00

Let me brief you the whole requirement first. I have the following HTML code:

  • 0

Let me brief you the whole requirement first.

I have the following HTML code:

<div id="container">
  <ul>
    <li style="background-color:#CCC">One</li>
    <li style="background-color:#CCC">Two</li>
    <li style="background-color:#CCC">Three</li>
    <li style="background-color:#CCC">Four</li>
    <li style="background-color:#999">Five</li>
    <li style="background-color:#666">Six</li>
    <li style="background-color:#000; color:#FFF;">Seven</li>
    <li style="background-color:#000; color:#FFF;">Eight</li>
  </ul>
</div>    

CSS is like below:

<style type="text/css">
    #container { width:960px; overflow:hidden; margin:0 auto; border:1px dotted #CCC;}
    #container ul { padding:0; margin:0; white-space:nowrap; }
    #container li { list-style-type:none; display:inline-block; text-align:center; padding:0 15px; line-height:32px; margin:0; }
    * html #container li { display:inline; text-align:center; }  /* IE6 hack */
    * html #container { padding-bottom:17px;}  /* IE6 hack  */
    *:first-child+html #container li { display:inline; } /* IE7 hack */
    *:first-child+html #container { padding-bottom:17px; overflow-y:hidden; }  /* IE7 hack  */
</style>    

Now, we need to make the top navigation with LI – display:inline property. Condition is, in any scenario the menu will cover the 100% percent of the width. So each menu item will contain equal width. If there is One menu item then also it should cover 100% width.

I have achieved the same from the following code:

<script type="text/javascript">
    $(document).ready(function(){
        var w = 0;
        var tw = 960;
        var cal_width =0;
        w = $('li').size();
        cal_width = (tw/w)-30 + "px";
        $("ul > li").css({"width": cal_width});
    });
</script>    

Each LI will get equal width.

Now, what we need to do is like there are maximum of 7 items can appear in the top navigation at once. So, if the menu items exceeds the limit of 7 then a seperate UL will get generated on the run to wrap the items which are like 8th, 9th & so on.

By calculating the number of lines, we can run a for loop in jquery to generate UL tags on the run to wrap extra LI items which are greater then 7.

Can somebody help me out with this problem ?

  • 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-15T23:46:50+00:00Added an answer on May 15, 2026 at 11:46 pm

    You could re-write the HTML of the initial DIV, might not be the best but would do the job, run this before you apply the classes.

    var childCount = $("#container li").length;
    if (childCount > 7) {
        var i=1;
        newHtml = "";
        $.each($("#container li"), function() { 
            if (i == 1) {
                newHtml +="<ul>";
            }
            newHtml += "<li>" + this.innerHTML + "</li>";
            if (i >= 7) {
                newHtml +="</ul>";
                i=1;
            } else {
                i++;
            }   
        });
        }
    $("#container").html(newHtml)
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say i have this block of code, <div id=id1> This is some text
Let's say you have a class called Customer, which contains the following fields: UserName
Let's say that we have an ARGB color: Color argb = Color.FromARGB(127, 69, 12,
My first question here so let's be brief. I am parsing this site: http://78.133.214.226/fotoweb/Grid.fwx
I have following code (only relevant portions shown for sake of brevity - please
I had a confusion let me explain it in brief. I have a form
Let's put Heisenberg aside for a brief moment. How would I go about to,
Let's say you create a wizard in an HTML form. One button goes back,
Let's say I'm building a data access layer for an application. Typically I have
Let me try to explain what I need. I have a server that is

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.